做了2年前端,底子虚浮,无根之浮萍。2年时间里写的代码不知道多少行了。越写越觉的对前端理解不够。又找不到什么切入方向。css、js不断更新。2只鞋子都没穿好。在前端路上也能走,走了2年了,混到写不动也没关系。但是还是想穿好鞋子后在前端路上npm run。。。。
怎么学呢。由点到面吧。英文看不懂。书拿到手里就困。万万是读不下去的。
class person {
constructor(name, age) {
this.sex = 'man',
this.name= name;
this.age = age;
this.say = function() {
console.log(`i am ${this.name}, i ${this.age}`)
}
}
}
var obj = new person('bird', 16);
console.log(obj)
// new 的作用
// 1 创建一个空对象
// 2 将构造函数的作用域赋予给新对象 (因此this的指向就指向了新对象)
// 3 执行构造函数中的代码(为这个对象添加属性)
// 4 返回新对象
class person {
constructor(name, age) {
this.sex = 'man',
this.name= name;
this.age = age;
this.say = function() {
console.log(`i am ${this.name}, i ${this.age}`)
}
}
}
var newObj = {}
console.log(1)
console.log(newObj)
newObj.__proto__ = person.prototype
console.log(2)
console.log(newObj)
newObj.name = 'bird'
console.log(newObj)
console.log(newObj.name)
console.log(newObj.sex)
person.call(newObj)
console.log(3)
console.log(newObj)
引出的问题
1, class 的继承 运用
2,prototype proto 之间的关系
3,call(),bind(),apply()