rajakvk
rajakvk

Reputation: 10123

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 know this belongs to a wiki discussion. If so please guide me to change this so.

Upvotes: 1

Views: 109

Answers (4)

user113716
user113716

Reputation: 322492

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.

Upvotes: 1

ajreal
ajreal

Reputation: 47321

length is a property inherit from javascript

size() is a method

Upvotes: 1

Oliver M Grech
Oliver M Grech

Reputation: 3171

size returns length. Length is a bit faster.

Upvotes: 0

Related Questions