Howto isset Method? without initilize instance - Javascript
This is a discussion on Howto isset Method? without initilize instance - Javascript ; 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....
-
Howto isset Method? without initilize instance
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.
-
Re: Howto isset Method? without initilize instance
On May 11, 11:42 am, "mabo...@" <mabo...@> wrote:
> 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);
--
Rob
-
Re: Howto isset Method? without initilize instance
RobG wrote:
> On May 11, 11:42 am, "mabo...@" <mabo...@> wrote:
>> 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);
Is that a magic trick? 
--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
-
Re: Howto isset Method? without initilize instance
On May 11, 1:17 pm, -Lost <maventheextrawo...@techie.com> wrote:
> RobG wrote:
> > On May 11, 11:42 am, "mabo...@" <mabo...@> wrote:
> >> 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);
>
> 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.
--
Rob
-
Re: Howto isset Method? without initilize instance
RobG wrote:
> On May 11, 1:17 pm, -Lost <maventheextrawo...@techie.com> wrote:
>> RobG wrote:
>>> On May 11, 11:42 am, "mabo...@" <mabo...@> wrote:
>>>> 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);
>> 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.
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. 
--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Similar Threads
-
By Application Development in forum RUBY
Replies: 8
Last Post: 11-26-2007, 02:33 PM
-
By Application Development in forum c++
Replies: 8
Last Post: 09-19-2007, 10:54 PM
-
By Application Development in forum Python
Replies: 12
Last Post: 08-27-2007, 10:08 AM
-
By Application Development in forum Python
Replies: 2
Last Post: 08-22-2007, 11:19 AM
-
By Application Development in forum DOTNET
Replies: 1
Last Post: 08-16-2007, 08:18 PM