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

KnockoutProperty.createArrayMethod should no longer splice the property array. #1625

Open
briandipalma opened this issue Dec 11, 2015 · 0 comments

Comments

@briandipalma
Copy link
Contributor

Inside KnockoutProperty we have this code,

KnockoutProperty.createArrayMethod = function(sMethod) {
    return function() {
        var pUnderlyingArray = this.getValue();
        var pNewArray = pUnderlyingArray.splice(0, pUnderlyingArray.length);
        Array.prototype[sMethod].apply(pNewArray, arguments);
        this.setValue(pNewArray);
    };
};

Which performs a splice on the KO property array. This means that an array provided to the property would end up being mutated during any array operation performed on the property. When creating a
Property and providing it an array you might be surprised to see the array you provided mutated. This array
could be an array of application wide configuration for example, which when modified could lead to weird
bugs. Does it seem reasonable to instead do a slice on the array, thus preserving the original array?

@briandipalma briandipalma changed the title KnockoutProperty.createArrayMethod should no longer splice the property array. KnockoutProperty.createArrayMethod should no longer splice the property array. Dec 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant