seznam / JAK

JAK je kompaktní a jednoduchý systém volně provázaných knihoven, usnadňující práci v prostředí jazyka JavaScript.
Other
49 stars 29 forks source link

Add childIndex property #137

Closed eorroe closed 9 years ago

eorroe commented 9 years ago

The childIndex property would return the index of that child Element from parent

Object.defineProperty(Node.prototype, 'childIndex', {
    get() {
        var currentElement = this.parentElement.firstElementChild, index = 0;
        while(currentElement.nextElementSibling) {
            if(this == currentElement) {
                return index;
            } else {
                index++;
                currentElement = currentElement.nextElementSibling;
            }
        }
    }
});
ondras commented 9 years ago

Is this a standardized API? Can you point me to some official docs for this?

eorroe commented 9 years ago

No it's not, it's an idea.

ondras commented 9 years ago

Ah. Well, even if the idea is useful (it is, in this particular case), we try to modify native prototypes only by adding standardized APIs (polyfills) to avoid potential namespace clashes and forward compatibility issues.

eorroe commented 9 years ago

Oh I saw this reference from mdn, which is under development I believe so I thought why not suggest the idea here, instead of in specifiction.org.