What are the differences between size() length in jquery

零下一度
Release: 2017-06-17 17:50:15
Original
1622 people have browsed it

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 isattribute?

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 ofobject, 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 afunctioncall

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!