Relfection in Javascript?
Posted: Tue Sep 26, 2006 12:29 am
Is there a way I could get an object to return some data about itself to me? That would be reflection, correct?
Would I be able to use the prototype thing for osmething like this?
I am passing an object to a method in another object, I need to know at least the name of the object being passed.
If possible I would like to find out what methods that object has.
I am trying to use an observer-like thing for this thing I am doing.
I know that I am not being clear enough about this. (intoxicated, lolo. first time i've felt like working in a while)
So, have some code:
I woudl like to check what those objects are when they are passed and when it is called in the GetWeblog() function.
Possible?
Would I be able to use the prototype thing for osmething like this?
I am passing an object to a method in another object, I need to know at least the name of the object being passed.
If possible I would like to find out what methods that object has.
I am trying to use an observer-like thing for this thing I am doing.
I know that I am not being clear enough about this. (intoxicated, lolo. first time i've felt like working in a while)
So, have some code:
Code: Select all
Request=
{
http : false,
xmldom : false,
init : function()
{
this.CreateXmlHttpRequestObject();
if (this.http == false)
{
alert('Your browser does not support AJAX functionality.\nYou are now being redirected to the non-AJAX version of the website.')
window.location = window.location + "no_ajax/"; (lols?)
}
},
CreateXmlHttpRequestObject : function()
{ This makes the xmlrequest thing on the this.http variable },
CreateXmlDomObject : function ()
{ },
MakeRequest : function (method, url, obj)
{
this.http.open(type, url)
if (typeof obj == 'object')
{
this.http.onstatechange = obj.HandleResponse(
this.http.responseText,
this.http.ResponseXml);
}
else
{
this.http.onstatechange = this.HandleResponse();
}
},
HandleResponse : function ()
{
alert('This is a default behavior, there was an error.\n'+this.http.responseText);
}
}
Code: Select all
var Weblog=
{
url : 'weblog.php',
method : 'GET',
frame : 'contentFrame',
requestRef : null,
init : function (requestObj, frame)
{
if (frame)
{
this.frame = frame;
}
if (typeof requestObj == "object")
{
this.requestRef = requestObj;
}
},
GetWeblog : function ()
{
this.requestRef.MakeRequest(method, url+'?a=get&v=all', this); // Here's the line it stops on
// It says the method doesnt exist
},
HandleResponse : function (responseText, ResponseXml)
{ This is the DOM's new girlfriend }
}
Possible?