javascript - Is is safe to use function reference as an object property/key -


this question has answer here:

are there reasons why should not use function reference property/key of object ? code works in chrome, firefox, & ie8, "just because works..."

var x = {}  var = function() { return 'a' }; var b = function() { return 'b' };  x[a] = 1 x[b] = 2  x[a] === x[a] // returns true x[a] === x[b] // returns false x[b] === x[b] // returns true x[a] // returns 1 x[b] // returns 2 

object keys string. used in x[a] in fact x[a.tostring()].

this means function key same key string :

x[a] === x["function () { return 'a' }"] 

so yes, might consider both unsafe , unreasonable. it's hard imagine context in useful or efficient.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -