看了一下关于prototype的文章,但是,太书面化了,不易理解,我将prototype还原成类对象,和大家分享一下,如果不对,欢迎拍砖!
测试代码 1
测试代码 2
///原型对象
public class prototype
{
//attribute
public object constructor;
//init
public prototype(constructor)
{
self.constructor = constructor;
}
//调用 prototype
public object prototype()
{
return this.parent; // prototype
}
//设置prototype值
public void .=(key,value)
{
set(key,value);
}
}
///Function对象
public class function : prototype
{
//attribute
public ArrayArguments arguments;
public object prototype = prototype();
//init
public function()
{
//调用基类
super(this);
//建立初始化属性
//处理 arguments
}
//call me
public callee()
{
function();
}
}
测试代码 1
function abc()
{
};
function cba()
{
this.c = "cba.prototype";
}
cba.prototype.d="d";
//abc对象继承cba对象
abc.prototype = new cba();
//实例化ABC对象
var obj = new abc();
abc.prototype.c = "abc.prototype";
obj.c = "self";
//打印对象间继承关系
alert(obj.c);
alert(abc.prototype.c);
alert(abc.prototype.d);
alert(obj.d);
测试代码 2
function abc()
{
};
var obj = new abc();
obj.c = "self";
//打印对象属性
alert(obj.c);
//打印继承prototype对象属性
alert(abc.prototype.c); //undefine
abc.prototype.c = "abc.prototype";
alert(obj.c); //self
alert(abc.prototype.c); //"abc.prototype";