C
Calm_Pear
Hi all,
I have created an object with a default function; the default function
exposes a public function as well.
myobject = function(){
var objects = [];
function addLoad(func){var oldonload = window.onload;if(typeof
window.onload != 'function'){window.onload = func;}else{window.onload =
function(){if(oldonload){oldonload();}func();}}}
function object(div){
/* some code here */
}
return function(div){
addLoad(function(){objects.push(new object(div))});
myobject.test = function(txt){alert(txt);};
}
}();
object("mytextbox");
How would I reference the object itself in such a way that I do not have to
use the object name?
Meaning; I'd like to get rid of:
myobject.test = function(txt){alert(txt);};
And have it read something like:
this.test = function(txt){alert(txt);};
(but that will add the function to the window object which is something I do
not want)
Or
var that = this;
that.test = function(txt){alert(txt);};
(but that doesn't work also...)
My guess is you can't because the object is being created as the page loads
and there is no way to get its name until it's finished creating. (I don't
like to add the function(s) with prototype because the function should
operate as a singleton anyway and it... well... just looks wrong I guess)
Regards
I have created an object with a default function; the default function
exposes a public function as well.
myobject = function(){
var objects = [];
function addLoad(func){var oldonload = window.onload;if(typeof
window.onload != 'function'){window.onload = func;}else{window.onload =
function(){if(oldonload){oldonload();}func();}}}
function object(div){
/* some code here */
}
return function(div){
addLoad(function(){objects.push(new object(div))});
myobject.test = function(txt){alert(txt);};
}
}();
object("mytextbox");
How would I reference the object itself in such a way that I do not have to
use the object name?
Meaning; I'd like to get rid of:
myobject.test = function(txt){alert(txt);};
And have it read something like:
this.test = function(txt){alert(txt);};
(but that will add the function to the window object which is something I do
not want)
Or
var that = this;
that.test = function(txt){alert(txt);};
(but that doesn't work also...)
My guess is you can't because the object is being created as the page loads
and there is no way to get its name until it's finished creating. (I don't
like to add the function(s) with prototype because the function should
operate as a singleton anyway and it... well... just looks wrong I guess)
Regards