我正在寻找类似的东西:
document.getElementById("id").innerText.toString().length;
所以 : class.method1().method2().method3();
我的代码:
class Example
{
method1(){ .. }
method2(){ .. }
method3(){ .. }
}
从课外:
var element = new Example();
element.method1(); //works fine
element.method1().method2(); // error: method2 is not defined
有什么办法吗?
谢谢大家:)
您正在寻找的被称为流畅接口。要实现此目的,只需将其添加return this;
到类中每个方法的末尾。
旁注:document.getElementById("id").innerText.toString().length;
不是一个流畅的界面-每个函数/属性都返回一个不同的值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句