Javascript JQuery chaining

六眼飞鱼酱① 提交于 2020-01-16 00:45:25

问题


Let's say we have :

$("p")[0].innerHTML;

and

$("p").html();

In the above examples, we have the same result. So I was wondering how can JQuery return both the nodelist and itself to allow chaining ?


回答1:


So I was wondering how can JQuery return both the nodelist and itself to allow chaining ?

It doesn't.

It only returns itself (which it an object).

That object has a property called 0 which contains the first element in the array of elements. It also has a property called html which contains a function.




回答2:


that is called fluent syntax. each function returns the object it is given. something like

function f(obj){
    doSomething(obj);
    return obj; 
} 


来源:https://stackoverflow.com/questions/34920816/javascript-jquery-chaining

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!