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
You can see from the picture that the size() method is 38% slower than length. What is the reason?
The reason is:
, you can see that the essence of size() is implemented by calling the length attribute ofobject, and The official website explains it this way:
, 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!