Home  >  Article  >  Web Front-end  >  Detailed explanation of the difference between size() length in jquery

Detailed explanation of the difference between size() length in jquery

零下一度
零下一度Original
2017-06-19 13:19:321235browse

size() has the same function as length, both get the number of elements, so what is their difference? One is a method and the other is attribute?

Let’s take a look at their execution time first, http://jsperf.com/size-vs-length uses this detection

jquery 中size() length的区别

You can see from the picture that the size() method is 38% slower than length. What is the reason?

The reason is:

jquery 中size() length的区别

, you can see that the essence of size() is implemented by calling the length attribute of object, and The official website explains it this way:

jquery 中size() length的区别

, which means that in jquery 1.8, size() is replaced by length. The functions of size() and length are equivalent, but length is more Excellent, because he does not need to return a function call

The above is the detailed content of Detailed explanation of the difference between size() length in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn