开发者

Why jquery defined two methods for the same purpose? size and length

After reading this SE Discussion a question pops up. Why jquery defined two methods for the same purpose? Is there any purpose I missed?

Don't k开发者_JAVA百科now this belongs to a wiki discussion. If so please guide me to change this so.


I would guess someone just didn't think it through, unless perhaps the earliest versions had some reason. I could only find source back to 1.2.6, and it is unchanged from the current version.

EDIT: It seems to have been unchanged since version 1.0.1.

The documentation for .size() suggests that it should not be used.

You should use the .length property instead, which is slightly faster.


length is a property inherit from javascript

size() is a method


size returns length. Length is a bit faster.


"most likely implemented to abstract away from the possibility of the length property being changed"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜