小编Ric*_*ick的帖子

数组属性如何在JS对象中工作

对于下面的代码,为什么propBmyObj更新?为什么test.childObj没有自己的财产propB

var myObj = { propA: '', propB: [] }
var fatherObj = {
    childObj: null,
    init: function() {
        this.childObj = Object.create(myObj);
        this.childObj.propA = 'A';
        this.childObj.propB.push(2);
    }
}

var test = Object.create(fatherObj);
test.init();

console.log(myObj.propB.length);
console.log(test.childObj.hasOwnProperty('propA'));
console.log(test.childObj.hasOwnProperty('propB'));
Run Code Online (Sandbox Code Playgroud)

javascript

11
推荐指数
1
解决办法
737
查看次数

标签 统计

javascript ×1