function doSomething () {
console.log(doSomething)
}
class Parent {
custructor(options) {
// 构造函数,在生成实例时,会调用
this.options = options
this.doSomething = doSomething;
}
// 挂在原型链下,如果有子类继承该类,也能访问
sayHi() {
console.log('hi')
}
// 挂在Parent下,不会在子类里重复初始化,只保存一份,可以通过原型链访问,Parent.things
static things = '手机'
// 加不加public我理解都一样,挂在原型链下,如果有子类继承该类,也能访问修改
public sayYes() {
console.log('yes')
}
// 私有属性或方法,实例无法直接访问,可以间接访问,比如实现一个公共方法来修改访问,实例可以调用公共方法实现修改
private noCount = 0
sayNo() {
console.log('no')
noCount += 1
}
}
function doSomething () {
console.log(doSomething)
}
function Parent(options) {
this.options = options;
this.doSomething = doSomething;
var _noCount_ = 0;
}
Parent.things = '手机'
Parent.prototype.sayHi = function(){
console.log('hi')
}
Parent.prototype.sayYes = function(){
console.log('yes')
}
Parent.prototype.sayNo = function(){
console.log('no')
_noCount_ += 1
}