user3448187
user3448187

Reputation:

How to "use strict" for a class within an anonymous function?

I'm trying to build a library that uses strict.

/*jslint */
(function() {
    'use strict';

    function MyLibrary() {

    }

    MyLibrary.prototype.add = function () {

    }
}());

var usersLibrary = new MyLibrary();

I'm trying to stick with the classical syntax for instantiating classes (using "new"). Unfortunately, I can't call myLibrary because it's scope is within the function.

Upvotes: 0

Views: 83

Answers (1)

Pointy
Pointy

Reputation: 413826

Explicitly add it to the global context:

(function(global) {
    'use strict';

    function myLibrary() {

    }

    myLibrary.prototype.add = function () {

    }

    global.myLibrary = myLibrary;
}(this));

Upvotes: 2

Related Questions