前端笔试题2:构造函数实现继承
文章目录
// 父类
function father() {
this.hobbies = ["music", "reading"];
}
// 子类
function child() {
father.call(this);
}
var c1 = new child();
var c2 = new child();
c1.hobbies.push("swimming");
console.log(c1.hobbies); // music reading swimming
console.log(c2.hobbies); // music reading
本文出现的代码都是自学,然后整理出来的
本人属于入门前端不久的小白,所以代码仅供参考!!!
有错误的欢迎指正,感谢