oop - Question about Javascript properties and instances -
i can't figure out myself why foo.bar in example undefined, explain?
var foo = "foo"; foo.bar = "baz"; console.log(foo.bar); // undefined q2: how add references properties , methods string instance foo?
help appreciated, thanks.
-- edit --
note: question generic string instance, not string global object. using "classic" prototyping suggested not option, because way every string instance have property called bar, while want augment instances.
this duplicate of why can't add properties string object in javascript?.
basically, you're creating string, , primitive type in javascript.
you cannot add properties primitive types in javascript.
Comments
Post a Comment