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

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -