I have the following object:
var IOBreadcrumb = {
breadcrumbs: [],
add: function(title, url){
var crumb = {
title: title,
url:url
};
this.breadcrumbs.push(crumb);
}
};
How can I access the object?
var breadcrumb = new IOBreadcrumb();
breadcrumb.add('some title','some url');
console.log(breadcrumb.breadcrumbs);
Gives me an Uncaught Type Error: object is not a function error.
The problem is you’re trying to use
newon an object but it can only actually target functions. Try the following insteadAlternatively you could also take advantage of the prototype here and share the definition of
addamongst several instancces