Basically can I do the following...
var obj = {}:
obj.falsey = true;
if(obj){
//code not executed
}else{
//code executed
}
I could ta
You can use loose equal to compare it to a boolean. People do that all the time, and finally it serves some purpose.
var obj = {valueOf: function() {return !this.falsey;}};
obj.falsey = true;
if (obj == true) {
//code not executed
} else if (obj == false) {
//code executed
}
No, you can't. You have to implement some custom logic.
You can borrow a false Number
,Boolean
.... from an iframe and extend its prototype.
Basically the following doesn't work because Numbers are a primitive value.
var x = 0;
x.test = 'yo';
console.log(x.test);
This does, but obviously this pollutes the Number.prototype, so you should really borrow a different Number
object from another iframe.
var x = 0;
Number.prototype.test = 'yo';
console.log(x.test);
Ultimately, just not a very good idea.