I am creating the following object:
var IOBreadcrumb = {
breadcrumbs: []
add: function(title, url){
var crumb = {title, url};
this.breadcrumbs.push(crumb);
}
};
I am getting an unexpected identifier error. Not really sure where it is ing from, its in this block of code.
I am creating the following object:
var IOBreadcrumb = {
breadcrumbs: []
add: function(title, url){
var crumb = {title, url};
this.breadcrumbs.push(crumb);
}
};
I am getting an unexpected identifier error. Not really sure where it is ing from, its in this block of code.
Share Improve this question asked Oct 5, 2011 at 23:08 Sheehan AlamSheehan Alam 61k126 gold badges359 silver badges561 bronze badges 2- jslint is your friend. It will give you line and column numbers of your syntax error. – hurrymaplelad Commented Oct 5, 2011 at 23:13
- @hurrymaplelad No need for an external tool. The browser itself does give you the line number of the error (and other details). – Šime Vidas Commented Oct 5, 2011 at 23:21
2 Answers
Reset to default 3You need a ma between members of your object, which is the cause of the error you cite. You also need to put a colon, rather than a ma, between the key-value pair in the crumb
object.
var IOBreadcrumb = {
breadcrumbs: [], // <-- ma here
add: function(title, url){
var crumb = {title: url}; // <-- colon here
this.breadcrumbs.push(crumb);
}
};
If you want an object where there are two members, one the title and one the URL, you may want something like this:
var crumb = {
title: title,
url: url
};
I don't know whether that would work with your breadcrumbs
setup...
I believe you want this:
var IOBreadcrumb = {
breadcrumbs: [],
add: function ( title, url ) {
var crumb = {};
crumb[ title ] = url;
this.breadcrumbs.push( crumb );
}
};