我想知道一个具有属性的对象是否是一个好的设计,该属性将继承与对象相同的原型。请考虑以下代码:
let Sme = {
e164Addr,
ton,
normalise : function(){
// normalise e164Addr to international
this.ton = 1;
return 0;
}
}
let Sim = Object.create(Sme);
Sim.setIMSI = function(imsi){
this._imsi = imsi;
}
Sim.getIMSI = function(){
return this._imsi;
}
Sim.setLocation = function(vlrAddr, ton){
this._vlr = Object.create(Sme);
this._vlr.e164Addr = vlrAddr;
this._vlr.ton = ton;
this._vlr.normalise();
}
Sim.getLocation = function(){
return this._vlr;
}
function createSim(msisdn, ton){
let sim = Object.create(Sim);
sim.e164Addr = msisdn;
sim.ton = ton;
return sim;
}
let sim = createSim('359883123456', 1);
sim.setLocation('359881234567', 1);
我正在谈论其__proto__为Sme的sim._vlr属性(与Sim&#39相同)。