Javascript classes with Webpack append Namespace

Viewed 28

I use Webpack to bundle my js files and as js preprocessor bubble. I try to sort my code, i will to use better classes with namespaces. But i cannot append my global namespace bb:

Main.js

var bb = bb || { version: '1.0.0' };
require('./js/Test'); 
var point = new bb.Point(12,13);

Test.js

(function(global) {
    'use strict';

    var bb = global.bb || (global.bb = { });

    console.log(bb);

    if (bb.Point) {
        console.log('bb.Point is already defined');
        return;
    }

    bb.Point = Point;


    function Point(x, y) {
        this.x = x;
        this.y = y;
    }

    Point.prototype = {

        type: 'point',

        constructor: Point,

        setXY: function (x, y) {
            this.x = x;
            this.y = y;
            return this;
        },
    };
});

Uncaught TypeError: bb.Point is not a constructor
0 Answers
Related