UzendayoNE
UzendayoNE

Reputation: 161

How can I solve "Cannot call method "addL" of undefined"

I was trying to make by myself a "library" for my personal project which uses local storage for nearly everything and I got this error.

The Browser I am using is Google Chrome on the last version. It says no error line on the console and the error is:

TypeError: Cannot call method 'addL' of undefined.

JavaScript

function local (title) {
    var storeTitle = title;
    this.addL = function(lString) {
        var storeText = lString;
        localStorage.setItem(storeTitle, storeText);
    };
    this.removeL = function() {
        localStorage.removeItem(storeTitle);
    };
    this.getL = function () {
        localStorage.getItem(storeTitle);
    };
};

I can't find the error and when I google Cannot call method ... of undefined it shows a lot of pages but with different content, not the one I'm looking for. I found from Google Maps API to jQuery API.

I learned this "way" from another question here StackOverflow.

Upvotes: 1

Views: 51

Answers (1)

friedi
friedi

Reputation: 4360

You are missing the new keyword. So try this:

new local("locally").addL("stored")

Upvotes: 4

Related Questions