-
Notifications
You must be signed in to change notification settings - Fork 639
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
obj.hasOwnProperty undefined is not a function nodejs #468
Comments
Sorry, An example that causes problems is
Where extra is just a JSON object. |
@fotisp What do you mean that extra is a JSON object? I tried the following in node 0.12 and it works fine: var extra = require('./extra.json');
console.log(extra.hasOwnProperty('key')); and the output is This also shows that var extra = JSON.parse('{"key": "val"}');
console.log(extra.hasOwnProperty('key')); |
Does the JSON object you've got have a property
Could you provide a full test case that produces the error? |
This could also happen if the object does not have extra = Object.create(null) The safer way to handle this case would be to change https://github.com/mozilla/nunjucks/blob/master/src/lib.js#L271 to this: if(Object.prototype.hasOwnProperty.call(obj, k)) { --- the only issue with that is that it may break some older browser compatibility, so we'd need to add extra logic for that. |
@fotisp, can you check out @devoidfury's comments above? |
Hi @jlongster, I will try to take a look during the weekend and report back. |
Please note: For example in (and sorry for my English) |
I'm not convinced this is worth fixing, but if someone wanted to look into the browser-compatibility implications of the |
@carljm This is enough of a problem that ESLint has a rule about it. http://eslint.org/docs/rules/no-prototype-builtins This setting was enabled in v4 of Airbnb's widely (43k+ stars) used ESLint config. I have noticed some libraries, notably |
Hello,
I was noticing some discrepancies in some of the rendering of the nunjuck templates. After enough digging around I boiled it down to different nodejs versions between development and production. However the production machine has a more resent version of nodejs.
With version v0.12.x of node, this line
https://github.com/mozilla/nunjucks/blob/master/src/lib.js#L271
fails with TypeError: undefined is not a function.
Has anyone encountered this, is there any know workaround?
The text was updated successfully, but these errors were encountered: