Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array indexOf Polyfill error in oldie module #8346

Closed
zhy1stgg opened this issue May 17, 2018 · 2 comments
Closed

Array indexOf Polyfill error in oldie module #8346

zhy1stgg opened this issue May 17, 2018 · 2 comments
Assignees
Labels

Comments

@zhy1stgg
Copy link

@zhy1stgg zhy1stgg commented May 17, 2018

Array indexOf Polyfill in your modules/oldie.src.js

if (!Array.prototype.indexOf) {
    H.indexOfPolyfill = function(arr) {
        var len,
            i = 0;

        if (arr) {
            len = arr.length;

            for (; i < len; i++) {
                if (arr[i] === this) {
                    return i;
                }
            }
        }

        return -1;
    };
}

fixed with:

if (!Array.prototype.indexOf) {
    H.indexOfPolyfill = function(item) {
        var len,
            i = 0;

        if (item) {
            len = this.length;

            for (; i < len; i++) {
                if (this[i] === item) {
                    return i;
                }
            }
        }

        return -1;
    };
}
@sebastianbochan
Copy link
Contributor

@sebastianbochan sebastianbochan commented May 17, 2018

Hi @zhy1stgg
Thank you for the suggestion.

@TorsteinHonsi does it make sense for you too?

@KacperMadej
Copy link
Contributor

@KacperMadej KacperMadej commented May 17, 2018

Internal note:

Additionally, H.indexOfPolyfill

if (!Array.prototype.indexOf) {
H.indexOfPolyfill = function (arr) {
var len,
i = 0;
if (arr) {
len = arr.length;
for (; i < len; i++) {
if (arr[i] === this) {
return i;
}
}
}
return -1;
};
}

doesn't support fromIndex.

H.inArray = function (item, arr, fromIndex) {
return (
H.indexOfPolyfill ||
Array.prototype.indexOf
).call(arr, item, fromIndex);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants