intellij idea - Is it okay to use "create" as a property name in a JavaScript object literal? -


i noticed idea / jshint telling me object literal contains property named "create" overrides method in object.

the literal essentially:

module.exports = {email:{create:"me@me.com"}}; 

and (obviously?) object has create method defined in ecmascript5.js

/** @param {object} proto @param {object} [props] @static @return {object} */ object.create = function(proto,props) {}; 

is cause obscure problem down line? i'm guessing reserved method doesn't apply literals, or objects haven't been instantiated default constructor. curious.

the existing answers correct missing important detail. doing absolutely fine , not cause errors in javascript environment.

the object.create method that's been mentioned numerous times static, means property of object constructor itself, rather prototype. not overwriting it, or shadowing it. still 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 other static analysis tool warn against use of create property identifier, except perhaps reason cause potential confusion.

even concern create being reserved word in javascript non-issue because modern javascript environments allow use of reserved words property identifiers, , create not reserved word in first place:

var obj = {   default: 1 // reserved word identifier }; 

so in summary, safe ignore warning , don't worry potential side-effects code might have had.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -