/    Sign up×
Community /Pin to ProfileBookmark

Prototype problem + onload

Hello all from Sweden.

I’m working on a system in OOP Javascript. I have some big problems
with this prototype thing…

It’s really confusing. BTW, this is a Firefox only problem, none of the other browser are important for this system. Anyway this is what i got right now:

function sysInit() {
this.objDOMWindow = window;

// I believe this one is missplaced…
// If i remove it, the code run flawlessly without inheritance from mwas.
xreq.prototype = this;
}

window.onload = function () {
var mwas = new sysInit;
var mwasreq = new xreq();

// This is were my problem arise.
// In firefox the error says: mwasreq.send is not a function.
mwasreq.send();
}

function xreq(){
if(window.XMLHttpRequest) {
try {
this.req = new XMLHttpRequest();
} catch(e) {
return false;
}
}
}

xreq.prototype.send = function (){
// Works without xreq.prototype = this; in sysInit…
alert(this.req);

// Does not work! In any way…
alert(this.objDOMWindow);

}

Hope some OOP Javascript guru can help me out.

?

Best regards
Adrian

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoMay 22.2006 — I have heard of objDOM, but what is objDOMWindow?
Copy linkTweet thisAlerts:
@amccoolauthorMay 23.2006 — Hello!

Well its just my own definition of document.window.

I store it through a custom object witch holds all these things....

BTW, I fixed the prototype stuff, remember this one has only been tested in Firefox, so all other browsers might get confused... IE I guess. ?

This is my final code, perhaps someone else could get use of it.


function sysInit() {

this.objDOMWindow = window;

// I noticed that if I added "xmlrequest.prototype = new sysInit;"
// in the onload handler it was called when I created the mwas.req
// object. If any parameters should be sent through this function
// before creating mwas.xmlreq they would be lost.
// Example mwas.sysInit(name)

xmlrequest.prototype = this;

}


function xmlrequest () {

this.req = getRequest();

var lock=this;

this.req.onreadystatechange = function() {lock.processedRequest()}

function getRequest(){

try {

if(window.XMLHttpRequest) {

try {

return new XMLHttpRequest();

} catch(e) {

return false;

}

// branch for IE/Windows ActiveX version

} else if(window.ActiveXObject) {

try {

return ActiveXObject('Msxml2.XMLHTTP');

} catch(e) {

try{

return ActiveXObject('Microsoft.XMLHTTP');

} catch(e) {

return false;

}

}

}

} catch(e){

return false;

}

}

}


sysInit.prototype.processedRequest = function (){

// Now I can access this one inherit from instance of mwas(sysInit);

this.objDOMWindow = window;

if (this.req.readyState == 4) {

if(this.req.status == 200) {

if (this.req.responseText == 1) {

alert('Got back without errors.');

}

} else {

alert(this.req.statusText);

}

}


}


sysInit.prototype.sendRequest = function (){

this.req.open('POST', '../system/includes/publishpage.php', true);

this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

this.req.send('html=' + escape(this.objContentDocument.documentElement.innerHTML));

}


window.onload = function () {

mwas = new sysInit;

mwas.xmlreq = new xmlrequest();

}


?
×

Success!

Help @amccool spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...