Course.prototype.study = function() { console.log(`我要学习${this.name}, 价格是${this.price}`) }
这里的name和price不是变量,是对象的属性,这里的this指的是当前对象。
比如:
const a = new Course('xxx', 10) // 这时候this指向a const b = new Course('yyy', 20) // 这时候this指向b
const a = new Course('xxx', 10) // 这时候this指向a
const b = new Course('yyy', 20) // 这时候this指向b