我目前在js组件中工作,我想知道是否有更好的方法来连接javascript中的函数然后返回this。我有一个示例代码在这里工作,这就是我解决问题的方式。
function hi(){
console.log('hi');
return this;
}
function bye(){
console.log('bye');
return this;
}
function Test(){};
Test.prototype.hi = hi;
Test.prototype.bye = bye;
var x = new Test();
x
.hi() //hi
.bye(); //bye
Run Code Online (Sandbox Code Playgroud) javascript ×1