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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -