为class添加方法,对象合并
作者:
冬天的_太阳 | 来源:发表于
2020-03-31 19:05 被阅读0次 //
class Point {
toString() {
console.log("打印");
}
}
// 为类添加方法:方式一
Point.prototype.say = function() {
console.log(" 360");
};
// 为类添加方法:方式二 Object.assign 是对象合并的意思
Object.assign(Point.prototype, {
getName: function() {
console.log(" 852852");
},
getAge: function() {
console.log(" 85285289");
}
});
// this.say
Object.assign ( { name: '1',age: 2}, { si: 'status',age: 5220 })
class People {
say() {
console.log( " say");
}
};
let obj = new Point();
obj.toString();
obj.say();
obj.getName();
本文标题:为class添加方法,对象合并
本文链接:https://www.haomeiwen.com/subject/wheguhtx.html
网友评论