【发布时间】:2015-06-11 08:28:16
【问题描述】:
如果我在一个对象下设置一个函数,我只能像这样使用它一次
function handle(selector)
{
return{
elem:selector,
next:function(){
return (this.nextSibling.nodeType==1) ? this.nextSibling : this.nextSibling.nextSibling;
}
}
}
在这里我可以说handle.next() 这会起作用,但如果我想说handle.next().next().next() 我的问题是如何像jquery 那样以这种方式使用?
【问题讨论】:
-
定义一个类,并让所有函数返回该类的实例。
-
问题是如何?
-
只需从每个函数中返回 'this'。
-
更多关于流畅界面的信息en.m.wikipedia.org/wiki/Fluent_interface
标签: javascript oop object handle object-properties