How to make a short name for an Array property

I often have typos typing the word "length" and would like to make a short name for this property. For example, "len"

I can easily create an array method:

Array.prototype.len = function(){ return this.length }

but then I have to call [1,2,3] .len () with brackets ...
But how to make real estate? (and name it with [1,2,3] .len)

I tried something like this:

Array.prototype.len = (function(arr) {return arr.length})(this)

but this one is not displayed that way

Thanks in advance

+3
source share
1 answer

Define getteras follows:

Array.prototype.__defineGetter__("len", function() {
    return this.length;
});

var arr = [1, 2, 3];
arr.len // 3

( : , prototype . , JavaScript-/ , , .)

+2

All Articles