/ Published in: JavaScript
This can be tested using the following piece of code
var a = [1, 2, 3, 4, 5];
alert(a.size());
Expand |
Embed | Plain Text
if(typeof Array.prototype.size != 'function'){ Array.prototype.size = function(){ return this.length; } }
Comments
Subscribe to comments
You need to login to post a comment.

just an honest question, why would one go through the trouble of adding this method when it simple aliases a property? Typing the property name "length" and the method call "size()" are both 6 characters long and therefor save the user no typing.