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
Post a Comment