//初始化变量
var target = {}
//下面这段可以屏蔽
Object.defineProperties(target, {
sex: {
value: '男'
},
})
//对Object对象进行扩展方法
Object.prototype.setObjectAttrbute = function(key,value){
console.log('有人来设置你了,值为:' + value)
return this[key] = value
}
//再封装一层
Object.prototype.setAge = function(value){
return this.setObjectAttrbute("age",value)
}
//查看修改前属性
console.log(target.age)
//执行方法,两种方法结果一样
console.log(target.setObjectAttrbute("age",99))
console.log(target.setAge(99))
//查看新的target
console.log(target)
</script>
var dc = []var dc1 = {
type: "car",
value: 4,
clone: function () { return { type: this.type, value: this.value } }
}
for (var i = 0i <5i++)
{
dc1.value = i
dc.push(dc1.clone())
}
for (var i = 0i <5i++)
{
alert(dc[i].value)
}