override object accessot javascript -


i override accessor of javascript object instead of override should return fixed value.

eg.

var obj = {}; console.log(obj.someproperty) //will print undefined expected value false 

if property undefined there no way have return false default "falsey".

for example:

var obj = {}; if (!obj.someproperty) {         console.log("expression falsey"); } 

a more explicit way test truthiness use double bang operator:

var obj = {}; console.log(!!obj.someproperty) // print's undefined, evaluates false 

but in short, going after not work because in javascript cannot redefine undefined.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -