阮一峰的es6中说对象解构赋值可以取到继承的属性。同样,也可以取到继承的方法
const obj1 = {};
const obj2 = { fooo: 'bar', hello: function(){ console.log("hello")} };
Object.setPrototypeOf(obj1, obj2);
const { fooo, hello: helloo } = obj1;
console.log(fooo); // "bar"
helloo(); //hello
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.sayName = function () {
console.log("i am " + this.name);
}
function Student(name, age, grade) {
Person.call(this, name, age);
this.grade = grade;
}
Student.prototype = new Person();
const s1 = new Student("s1", 1, 1);
s1.sayName();
const { sayName: sayname } = s1;
console.log(sayname, s1);
sayname.call(s1);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。


