看过jq里面的链式调用,自己来实现一下。随便写的,理解就好。
let A = function() {
this.name = 'Jony'
this.age = '18'
this.sex = '男'
this.getName = function() {
console.log(this.name)
return this
}
this.getAge = function() {
console.log(this.age)
return this
}
this.getSex = function() {
console.log(this.sex)
return this
}
}
let a = new A()
a.getName().getAge().getSex()
思想就是返回this来继续调用其他的方法。