Re: public properties



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;
};

.



Relevant Pages

  • Re: public properties
    ... this keyword refers to the Window object! ... you assign function to an object's property, and then invoke it ... new fnName() ...
    (comp.lang.javascript)
  • Re: How to access javascript variable via MSHTML in Dephi?
    ... A JavaScript global variable is a property on the window object, ... accessible via late binding (IDispatch::GetIdsOfNames, Invoke). ... know enough Delphi to explain how to implement this technique there, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: public properties
    ... var o = new Obj; ... this keyword refers to the Window object! ... which I'm staying to operate with. ...
    (comp.lang.javascript)