I know that this feal crazy but is there a way to return a value when accessing not exist property of an object in Javascript
For example
function Func(){
this.msg='hello'
}
var obj= new Func();
alert(obj.msg) // hello
alert(obj.foo) // undefined
Are there a way for obj.foo
to return a defult value not undefined
rather than alert(obj.hasOwnProperty('foo'):obj.foo||'foo')