/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Keep getting ".. is not a constructor" – I don’t understand why.

In trying to create a browser object (which parses XML data and displays it in a ‘Finder’-esque manner) I’ve stumbled across a problem which I’m unable to solve. When I was trying to test the object Firebug kept giving me “Browser is not a constructor”.
The code that called the object constructor is as follows:

[CODE]
var b = new Browser(‘b’, ‘test’, ‘/runtime/browserdatacollections.php?sort=category’);
[/CODE]

and the code for the actual constructor itself (I haven’t included any properties) is:

[CODE]
function Browser(id, title, url) {
/*
Browser Object
Creates a browsing GUI for browsing files/collections/artwork et cetera. Starts hidden.
Properties
id : object id, must be the same as the name given to the variable calling it.
title : the title to be displayed (optional).
url : the data feed url.
Methods
toggleWindow : shows/hides the window
get_data : retrieves the data from the url specified.
write_data : parses and writes the data to the browser window.
open : performs all actions to open the browser window/display data.
show : shows the browser window.
hide : hides the browser window.
*/
this.id = id;
this.title = title;
this.url = url;

//Wrapper
document.write(“<div id='” + this.id + “_wrapper’></div>)”);
this.wrapper = $(‘wrapper’);

//Structure
this.titlebar = document.createElement(“div”);
this.titlebar.className = “browser_titlebar”;
this.wrapper.appendChild(this.titlebar);
this.titlebar.innerHTML = “<h1>” + this.title + “</h1>”;

this.browser = document.createElement(“div”);
this.browser.className = “browser_browseWindow”;
this.wrapper.appendChild(this.browser);
}
[/CODE]

Any help would be very much appreciated since this is an annoying obstacle.

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@trandrusMar 23.2009 — works ok for me using ffpc 3.0.7 and firebug 1.3.3. have you checked other browsers or ff versions? sometimes firebug is firebuggy.
Copy linkTweet thisAlerts:
@blue-eye-labsauthorMar 23.2009 — I get the same error using safari's debugger...
Copy linkTweet thisAlerts:
@blue-eye-labsauthorMar 23.2009 — Maybe an error with previous code? The debuggers don't show any parse errors though...
Copy linkTweet thisAlerts:
@trandrusMar 23.2009 — try using an anonymous function stored in a variable instead of a named function:
[CODE]
var browser = function(params) {

//etc.

}[/CODE]


or try a json approach:
[CODE]
var app = {
browser: function(params)
{
//etc.
}
};

var useragent = new app.browser(params);[/CODE]
Copy linkTweet thisAlerts:
@blue-eye-labsauthorMar 23.2009 — The thing is that all my other similarly scripted objects are done in the same way and don't give errors... For example:
[CODE]
function Uploader(name, fdeck) {
/*
Uploader Object
This creates a wrapper for handling the asynchronous upload of files.
Properties
nom : the object's name
number : the number of the object if one is used in the name (so that the oncomplete function can be properly executed using an identification number).
id : the unique id tag for the uploading portal.
ulform : the upload form.
url : where the form is sending the data.
_STATINT : the status check number, used for clearing the interval for the check_status method.
_STATSTR : the status string from the script.
target : the target iframe used for portalling the upload.
status : the object's status.
oncomplete : can set an oncomplete function.
icon : the "icon" used for displaying upload status.
Methods:
upload
Initiates the file upload from a given file input node, filename and additional tags (for the runtime script).
Usage: uploader.upload(HTML_INPUT_OBJ, String_Filename, Array_Add_tags)
update_icon:
Updates the icon for displaying progress.
*/
this.nom = name;
this.number = Number(name.match(/d/));
this.id = "uploader_" + this.nom + "_" + (new Date).getTime();
this.ulform = $(fdeck);
this.url = this.ulform.action;
this._STATINT = Number();
this._STATSTR = String();
this.target;
this.status = 0;
this.oncomplete;
this.icon;

this.target = document.createElement("iframe");
this.target.id = this.target.name = this.id;
this.target.style.width = this.target.style.height = "0px";
this.target.style.border = "none";
this.target.style.visibility = "none";
this.target.src = "about:blank";
this.target.contentEditable = true;
document.body.appendChild(this.target);

this.ulform.target = this.target.id;
}
[/CODE]
Copy linkTweet thisAlerts:
@trandrusMar 23.2009 — then i'd go through line by line and isolate the problem. its hard to tell with no context. document.write should be avoided since it's bound to the page load sequence. i'd also utilize more of the builtin jquery dom tools to simplify your procedure.
Copy linkTweet thisAlerts:
@blue-eye-labsauthorMar 23.2009 — I'm not entirely sure what you mean. My js knowledge is a little patchy since it's not my main language.
Copy linkTweet thisAlerts:
@trandrusMar 23.2009 — [CODE]
function Browser(id, title, url) {
/*
this.id = id;
this.title = title;
this.url = url;

document.write("<div id='" + this.id + "_wrapper'></div>)");
this.wrapper = $('wrapper');

this.titlebar = document.createElement("div");
this.titlebar.className = "browser_titlebar";
this.wrapper.appendChild(this.titlebar);
this.titlebar.innerHTML = "<h1>" + this.title + "</h1>";

this.browser = document.createElement("div");
this.browser.className = "browser_browseWindow";
this.wrapper.appendChild(this.browser); */
}
[/CODE]


then run it and see if it errors. if not:
[CODE]
function Browser(id, title, url) {

this.id = id;
/*this.title = title;
this.url = url;

document.write("<div id='" + this.id + "_wrapper'></div>)");
this.wrapper = $('wrapper');

this.titlebar = document.createElement("div");
this.titlebar.className = "browser_titlebar";
this.wrapper.appendChild(this.titlebar);
this.titlebar.innerHTML = "<h1>" + this.title + "</h1>";

this.browser = document.createElement("div");
this.browser.className = "browser_browseWindow";
this.wrapper.appendChild(this.browser); */
}
[/CODE]

etc. until you find the offending line. if you are instantiating this after the document loads, document.write might be causing the error. you also have an extra right paren:

document.write("<div id='" + this.id + "_wrapper'></div>)");

vs.

document.write("<div id='" + this.id + "_
wrapper'></div>");
Copy linkTweet thisAlerts:
@blue-eye-labsauthorMar 24.2009 — I tried commenting out the function body already. It still gives me "browser is not a constructor"... weird.

The reason I use document.write() by the way is so that I can insert the wrapper div (and everything else, subsequently) directly into the code [U]at that point[/U] in the page. It has worked in other functions, but I'm not sure why not this one.

I am curious about the mention of both json and jquery since I don't really know of them.
Copy linkTweet thisAlerts:
@blue-eye-labsauthorMar 24.2009 — For some ridiculous reason it seems that changing the name of the function solves the problem! Ridiculous!

Before I mark this as "solved" however, I think I should test!
×

Success!

Help @blue-eye-labs 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.19,
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,
)...