<script>
var stooge = {
    "first-name": "Jerome",
    "last-name": "Howard"
};
stooge['middle-name'] = 'Lester';
stooge.nickname = 'Curly';
//以上填充4个元素

if (typeof Object.beget !== 'function') {
     Object.beget = function (o) {
         var F = function () {};
         F.prototype = o;
         return new F();
     };
}
var another_stooge = Object.beget(stooge);


another_stooge['first-name'] = 'Harry';
another_stooge['middle-name'] = 'Moses';
another_stooge.nickname = 'Moe';
//以上填充3个元素

stooge.profession = 'actor';
//原型填充1个元素:因为本身another_stooge没有这个属性,所以到原型去寻找
another_stooge.profession    // 'actor'<br />
//如果本身有这个属性,就取这个属性
another_stooge.nickname    // 'Moe'

delete another_stooge.nickname;

another_stooge.nickname;    // 'Curly'
</script>

相关文章:

猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案