Howto isset Method? without initilize instance

M

maborak

loading..............



var a =function()
{
this.b=function(){};
}

//howto isset this.b ?
WITHOUT

var g= new a(); // without instance

var isset = g.b || false;




connection closed.
 
R

RobG

loading..............

var a =function()
{
this.b=function(){};

}

//howto isset this.b ?
WITHOUT

var g= new a(); // without instance

var isset = g.b || false;

I don't really get what you are on about, my guess is that you want to
test for g.b but don't know if g is defined in the first place. Maybe
you want:

var isset = !!(g && g.b);
 
L

-Lost

RobG said:
I don't really get what you are on about, my guess is that you want to
test for g.b but don't know if g is defined in the first place. Maybe
you want:

var isset = !!(g && g.b);

Is that a magic trick? ;)
 
R

RobG

Is that a magic trick? ;)

No, it's using the && (AND) operator as what Douglas Crockford calls a
"guard" operator.

The expressions inside the brackets are evaluated from left to right
until either one of them resolves to false (or its equivalent: null,
undefined or numeric zero) or the last expression is reached.

The value of the last expression evaluated is returned, whereupon !!
converts it to boolean false (if it is one of the previously mentioned
values) or true (for any other value).

Note that strings '0' (zero), 'false', 'null', etc. resolve to true.
 
L

-Lost

RobG said:
No, it's using the && (AND) operator as what Douglas Crockford calls a
"guard" operator.

The expressions inside the brackets are evaluated from left to right
until either one of them resolves to false (or its equivalent: null,
undefined or numeric zero) or the last expression is reached.

The value of the last expression evaluated is returned, whereupon !!
converts it to boolean false (if it is one of the previously mentioned
values) or true (for any other value).

Note that strings '0' (zero), 'false', 'null', etc. resolve to true.

Ah yes, in the survey. I had forgotten about that. To be honest I did
not quite understand it until your explanation. (Granted it is still
remarkably fuzzy.)

Thanks. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top