文章目录
js链式调用
- 概念:只有本对象才能调用,利用this作用域,返回this
- 例子:
class Cat{
constructor(name){
this.name = name;
this.run =function(){
console.log(name + ' run');
return this;
}
this.sing = function(){
console.log(name + ' sing');
return this;
}
this.stop = function(){
console.log(name + ' stop');
return this;
}
}
}
let c = new Cat('ken');
c.run().sing().stop();