Re: public properties
- From: kindy <kindy61@xxxxxxxxx>
- Date: Wed, 19 Sep 2007 11:13:49 -0000
On Sep 19, 6:25 pm, josh <xdevel1...@xxxxxxxxx> wrote:
On 19 Set, 12:17, kindy <kind...@xxxxxxxxx> wrote:
init in the obj doesn't called.
- - - - - - - - -
function Obj(){
this.id;
function init(){
this.id = 100;
}
init.call(this);}
var o = new Obj();
o.id;
- - - - - - - - -
and, i don't know why
init.call(this)
can't write as
init();
yes sorry I've forgotten to write it:
function obj()
{
this.id;
function init()
{
this.id = 100;
}
init();
}
however the this is undefined because in the private function the
this keyword refers to the Window object! and not to the object in
which I'm staying to operate with.
the keyword this in a function will be always refers to the window,
unless:
1. function is invoked by call(obj) or apply(obj);
2. you assign function to an object's property, and then invoke it
like obj.fnName()
function Obj(){
function init(){
this.id= 100;
}
this.t= init;
this.t();
delete this.t;
}
- - - - - - - - -
function Obj(){
function init(){
this.id= 100;
}
init.call(this);
}
- - - - - - - - -
function Obj(){
var _this= this;
function init(){
_this.id= 100;
}
init();
}
- - - - - - - - -
function Obj(){
this.init();
}
Obj.prototype.init= function(){
this.id= 100;
};
.
- Follow-Ups:
- Re: public properties
- From: kindy
- Re: public properties
- References:
- public properties
- From: josh
- Re: public properties
- From: kindy
- Re: public properties
- From: josh
- public properties
- Prev by Date: Re: 'ToolTip' code needed
- Next by Date: Re: Wait for loading in a frame
- Previous by thread: Re: public properties
- Next by thread: Re: public properties
- Index(es):
Relevant Pages
|