json實現(xiàn)對象
適用于單體對象讼渊,整個程序里只有一個催植,寫起來比較簡單
繼承
對象由屬性和方法組成
function A(){
this.user = "a";
}
A.prototype.getName = function(){
alert(this.user);
}
function B(){
//屬性的繼承
A.call(this);
}
// 方法的繼承
for(var i in A.prototype){
B.prototype[i] = A.prototype[i];
}
B.prototype.fn = function(){
alert("abc");
}
var a = new A();
var b = new B();
// B.prototype = A.prototype; // 引用傳遞 會帶來共享的問題 不符合繼承的特點 父親有的兒子全有 兒子有的父親可能沒有
alert(b.user);
b.getName();
b.fn();
a.fn(); // a.fn is not a function