我真的搜索了很多,但我没有找到合适的结果。
我想知道,MomentJs设计模式是什么?
它有点像Module Pattern,但最终通过Prototype公开了公共API
在917行:https://github.com/timrwood/moment/blob/master/moment.js#L917
moment.fn = Moment.prototype = ...谢谢你们。
发布于 2013-01-12 01:29:40
moment.js的很多应用程序接口设计都是受到jQuery的启发。
构造函数不需要new关键字,并接受各种输入。
moment.fn和jQuery.fn都是主原型的公开。
getters和setter都使用相同的名称空间,并根据是否提供输入来充当getter或setter。moment().date() vs moment().date(1),$().height() vs $().height(200)。
它们都使用方法链接,也称为fluent interface pattern。moment().date(1).month(5)和$().hide().addClass('something')。
https://stackoverflow.com/questions/14273546
复制相似问题