日期:2014-05-16 浏览次数:20589 次
var obj1={a:1,method:function(){return 123}}
var obj2={}
for (q in obj1){
obj2[q]=obj1[q]
}
alert(obj2.method())
//1.不是继承,是克隆
//2.继承的唯一写法
function A() {this.name1 = "a";}
A.prototype.getName1 = function(){return
this.name1;}
function B(){this.name2 = "b";}
B.prototype = new A();//通过prototype继承
B.prototype.constructor = B;//new B()后 对象的
构造方法是自己B
B.prototype.getName2 = function(){return
this.name2;}
var b = new B();
alert(b.getName1())
alert(b.getName2())
//3.克隆功能的可以写个公共方法
Object.prototype.clone = function()
{
//具体业务
}
var obj = new B();
obj.name2 = "2b";
alert(obj.clone().getName2());