javascript - Is it possible for an object to have one value when accessed directly and also nested object inside? -


i wondering if it's possible in javascript object property have following behaviour:

console.log(obj); // output 'something' console.log(obj.prop_a); // output 'a' 

and also

var = obj; // === 'something' var b = obj.prop_a; /// b === 'a' 

the object kind of have 2 versions, 1 when access directly, , 1 when access 1 of it's children props

thanks

yes, can override tostring() method:

obj.tostring = function() {     return "something"; } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -