2

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')

Ahmed Daif
  • 379
  • 3
  • 12
  • 2
    Probably this might help: http://stackoverflow.com/questions/20147081/javascript-catch-access-to-property-of-object – Axel Amthor Dec 30 '15 at 16:41

0 Answers0