• Hello,

    I'm trying to build my application as OOP, that's why I have parted all classes in different files. I have placed those files in modules directory.

    Example ;

    modules/connectionClass.js

    var connectionClass=function(){
        getVars=function(){
            return {social_id:Math.floor((Math.random() * 4)),text:zeroFill(Math.floor((Math.random() * 10) + 1),6)}
        };
    }
    

    modules/helper.js

    function zeroFill( number, width )
    {
        width -= number.toString().length;
        if ( width > 0 )
        {
            return new Array( width + (/\./.test( number ) ? 2 : 1) ).join( '0' ) + number;
        }
        return number + ""; // always return a string
    }
    

    projects/main.js

    require('connectionClass');
    
    var connection=new connectionClass();
    

    But at the line var connection=... I'm getting this error

    Uncaught Error: Field or method does not already exist, and can't
    create it on undefined at line x col y

    What I am doing wrong?

About

Avatar for fobus @fobus started