ES5中Object的扩展
"use strict";
var student={
school:"xxx High School",
name:"xxx",
position(){
console.log(this.name+"的职务是"+this.type);
}
};
var mintor=Object.create(student,{
type:{
value:"班长",
wirtable:false,
configurable:false,
enumerable:true
},
name:{
value:"jpc",
writable:true,
configurable:true,
enumerable:true
},
getName:{
value:()=>{
return this.name;
},
writable:false,
configurable:false,
enumerable:false
}
});
console.log(mintor);
var student={
name:"jpc"
};
Object.defineProperty(student,"age",{
value:19,
writable:true,
configurable:true,
enumerable:true
})
console.log(student);
var student={
firstName:"牛",
lastName:"一一"
};
Object.defineProperties(student,{
fullName:{
get:function (){
return this.firstName+this.lastName;
},
set:function (data){
this.firstName=data[0];
this.lastName=data[1];
}
}
});
console.log(student.fullName);
var student={
firstName:"牛",
lastName:"一一",
get fullName(){
return this.firstName+this.lastName;
},
set fullName(data){
this.firstName=data[0];
this.lastName=data[1];
}
};
console.log(student.fullName);
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。