以下示例中原型的用途是什么..
FlyingFlowers.Calendar.prototype = {
init: function( selector, context ) {
// Make sure that a selection was provided
selector = selector || document;
..........
},
};
答案 0 :(得分:0)
名为Prototype的JavaScript库的名称来自JavaScript原型。在JavaScript中,原型是提供继承的机制(与类相反)。
它用于向已定义的对象添加属性或方法(有点像扩展)。例如:
function myNewObject(){
}
myNewObject.prototype.myCustomAttr = "Hello";
instance = new myNewObject();
alert(instance.myCustomAttr); // alerts Hello