Would the filter() method gets first priority in the method chain?

问题内容:

Assume this method chain

$("label").css("color", "blue").add("input[name!='rose']").filter("[for!='snowdrop']").css("font-size", ".75em");

In the above method call chain a call to the filter() in place. Typically method calling order is first come first serve. But when there is a filter() like above would that get called before add() method?

问题评论:

3  
Javascript methods are always called in order.
    
@SLaks ok thanks : )
– NP Neil Footy
2 hours ago

答案:

答案1:

But when there is a filter() like above would that get called before add() method?

No, that would be impossible. When you have a().b().c(), what’s happening is that a is called, and it returns something; that something’s b property is called as a function, and returns something; that something’s c property is called as a function.

So as you can see, filter can’t be called before add in that chain, because filter is called on what add returns.

答案评论:

    
hello,, just curious can be situations this order of chain called gets differed ?
– NP Neil Footy
1 hour ago
    
@NPNeilFooty: It doesn’t matter which functions you call; Javascript always works the same way.
    
@NPNeilFooty: The order will only be different if you arrange the function calls differently.
    
@T.J. Crowder thank you it cleared a doubt i had : )
– NP Neil Footy
1 hour ago

原文地址:

https://stackoverflow.com/questions/47754565/would-the-filter-method-gets-first-priority-in-the-method-chain

Tags:

添加评论