javascript - Do I need to wrap `new Object()` when using Polymer default property function? -


the polymer 1.0 documentation states,

if default value should array or object unique instance, create array or object inside function.

do need wrap object constructors such new thing(params) in anonymous function?

this means library doesn't make effort in deciding whether property's value should value-copied when it's object reference.

the basics in javascript:

var c = function() { } c.prototype.property = {}; var = new c(); var b = new c(); a.property.value = "hello world" console.log(b.property); // object { "value": "hello world" } 

both a , b share reference same object reference. opposed to:

var c = function() {     this.property = {}; } var = new c(); var b = new c(); a.property.value = "hello world" console.log(b.property); // empty object 

a new object reference created each time object instantiated. aware of when working objects in javascript. , arrays in fact objects, play same rules.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -