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

Do not use hasOwnProperty for getting data from context #32

Closed
Koc opened this issue Jun 6, 2012 · 1 comment
Closed

Do not use hasOwnProperty for getting data from context #32

Koc opened this issue Jun 6, 2012 · 1 comment

Comments

@Koc
Copy link

Koc commented Jun 6, 2012

There are cases, when ViewModels are too complex and have inheritance. So hasOwnProperty would return wrong data (null in most cases)

                // Get the variable from the context
                if (object.hasOwnProperty(key)) {
                    value = object[key];
                } else if (object.hasOwnProperty("get"+capitalize(key))) {
                    value = object["get"+capitalize(key)];
                } else if (object.hasOwnProperty("is"+capitalize(key))) {
                    value = object["is"+capitalize(key)];
                } else {
                    value = null;
                }
// -->
                // Get the variable from the context
                if (key in object) {
                    value = object[key];
                } else if (object[("get"+capitalize(key)]) {
                    value = object["get"+capitalize(key)];
                } else if (object["is"+capitalize(key)]) {
                    value = object["is"+capitalize(key)];
                } else {
                    value = null;
                }
@justjohn
Copy link
Collaborator

justjohn commented Jun 6, 2012

Good point, I hadn't considered this. I'll fix it shortly.

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

2 participants