Object.prototype.toString = function() {
alert('Hello World')
}
const obj = {}
obj.toString() Object.prototype.toString = function() { alert('Hello World')}const obj = {}obj.toString()
function SuperType() {
this.foo = 'bar'
}
function SubType() {}
// 继承
SubType.prototype = new SuperType()
function SuperType() {
this.foo = 'bar'
}
function SubType() {
SuperType.call(this)
}
console.log(new SubType().foo) // bar
function SuperType() {
this.foo = 'bar'
}
SuperType.prototype.output = function() {
console.log(this.foo)
}
function SubType() {
SuperType.call(this) // 继承属性
}
SubType.prototype = new SuperType() // 集成方法
const subType = new SubType()
console.log(subType.foo) // 访问父级属性 bar
subType.output() // 访问父级方法 bar5
function SuperType() {
}
function SubType() {
SuperType.call(this) // 继承父类属性
}
SubType.prototype = Object.create(SuperType.prototype) // 取得父类的一个副本
SubType.prototype.constructor = SubType