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

Occurred error in 'set' and 'delete' utility functions #1809

Closed
wants to merge 6 commits into from

Conversation

kazupon
Copy link
Member

@kazupon kazupon commented Nov 15, 2015

we create the object with Object.create(null), and after that when we use Vue.util.set or Vue.util.delete, occur the following error at these functions.

TypeError: obj.hasOwnProperty is not a function. (In 'obj.hasOwnProperty(key)', 'obj.hasOwnProperty' is undefined)

Please see the following jsfiddle:
https://jsfiddle.net/kazupon/1b7nytcd/1/

This issue is related #1765

I fixed the this issue, and refactored.
Please check the PR!! 😸

@kazupon kazupon changed the title Occurred error in 'set' and delete utility functions Occurred error in 'set' and 'delete' utility functions Nov 15, 2015
* @return {Boolean}
*/
exports.hasOwnProperty = function (obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's cache Object.prototype.hasOwnProperty outside the function because this is going to be called a lot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, what I mean is just hold it in a variable outside the function as var hasOwn = Object.prototype.hasOwnProperty
It probably doesn't make much difference, but saves two property lookups on every call ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. :)

@yyx990803
Copy link
Member

Thanks! A few notes:

  1. The changes to v-model directives are unnecessary because those are Elements so they will always inherit from Object.prototype.
  2. Let's rename it to _.hasOwn (shorter and smaller file size)

@kazupon
Copy link
Member Author

kazupon commented Nov 16, 2015

Thank you for your many review!! :)

I'll try 💪

@kazupon
Copy link
Member Author

kazupon commented Nov 16, 2015

Done.
Please check :)

@yyx990803
Copy link
Member

Looks good! Can you squash them into one commit please?

@kazupon
Copy link
Member Author

kazupon commented Nov 16, 2015

See the #1816 :)

@kazupon kazupon closed this Nov 16, 2015
@kazupon kazupon deleted the fix/object-null branch November 16, 2015 11:11
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

Successfully merging this pull request may close these issues.

None yet

2 participants