I just noticed IDEA / JSHint telling me that an object literal which contains a property named "create" overrides a method in Object.
The literal is essentially:
module.exports = {email:{create:"me@me.com"}};
And (obviously?) Object has a create method defined in EcmaScript5.js
/**
@param {Object} proto
@param {Object} [props]
@static
@return {Object}
*/
Object.create = function(proto,props) {};
Is this something that could cause an obscure problem down the line? I'm guessing that this reserved method doesn't apply to literals, or objects which haven't been instantiated with a default constructor. Just curious.
The existing answers are correct but missing some important detail. What you are doing is absolutely fine and will not cause errors in any JavaScript environment.
The Object.create
method that's been mentioned numerous times is static, which means is a property of the Object
constructor itself, rather than its prototype. You are not overwriting it, or even shadowing it. It will still be accessible:
var obj = { create: 'something' };
console.log(obj.create); // 'something'
console.log(Object.create); // function create() { [native code] }
I'm not sure why JSHint or any other static analysis tool would warn against the use of create
as a property identifier, except perhaps for the reason that it could cause some potential confusion.
Even your concern about create
being a reserved word in JavaScript is a non-issue because modern JavaScript environments allow the use of reserved words as property identifiers, and create
is not a reserved word in the first place:
var obj = {
default: 1 // Reserved word as identifier
};
So in summary, you are safe to ignore the warning and don't worry about any potential side-effects your code might have had.