我倒不明白了//定义extend方法
Object.extend = function(destination,source) //(1)-的我理解是destination为子类,source为基类
{
for(property in source)
{
destination[property] = source[property];
} return destination;
}Object.prototype.extend = function(object) //(2)-object参数应该是表示的是基类的引用
{
return Object.extend.apply(this,[this,object]);
}两个都声明了extend方法,那extend不是被重载了么
根据代码来看,第一个应该是Object.extend.apply = function(destination,source){..}吧
Object.extend = function(destination,source) //(1)-的我理解是destination为子类,source为基类
{
for(property in source)
{
destination[property] = source[property];
} return destination;
}Object.prototype.extend = function(object) //(2)-object参数应该是表示的是基类的引用
{
return Object.extend.apply(this,[this,object]);
}两个都声明了extend方法,那extend不是被重载了么
根据代码来看,第一个应该是Object.extend.apply = function(destination,source){..}吧
/**
*这里定义的是Object静态方法,在使用时直接调用Object.extend(obj1, obj2)
*/
Object.extend = function(destination,source) //(1)-的我理解是destination为子类,source为基类
{
for(property in source)
{
destination[property] = source[property];
}return destination;
}/**
*这里定义的是实例方法,需new Class().extend(obj2)
*/
Object.prototype.extend = function(object) //(2)-object参数应该是表示的是基类的引用
{
return Object.extend.apply(this,[this,object]);
}//定义class1
function class1()
{
//构造函数
}
//
class1.prototype={
method:function()
{
alert("class1");
},
method2:function()
{
alert("method2");
}
}function class2()
{
//构造函数
}
class2.prototype=(new class1()).extend({
method:function()
{
alert("class2");
}
}); //(3)-这个地方我就不明白了:extend这里怎么会是一个函数呢?应该是基类啊,麻烦大家帮/**
*extend参数都是对象,上面定义的是个json对象,当能Class也是对象,他是Function的实例,而Function优势Object的实例
*/
{
//构造函数
}
class2.prototype=(new class1()).extend({
method:function()
{
alert("class2");
}
});上面一句话等于
var cls1 = new class1();
cls1.prototype.method = function() { alert("class2"); };
Object.extend(class2.prototype, cls1);