Skip to main content
added 124 characters in body
Source Link

Yes it is.

However, I had to rewrite your code a bit, as the method you're currently using appears to put the function calls into the global scope.

function MyClass(a, b){
    this.a = a;
    this.b = b;
};

function myClassInstance(){
    
    var//The objapply =function will apply MyClass attributes to this object.
    //The apply function itself returns nothing.
    MyClass.apply(this, arguments);
    console.log(this); //Should show the a and b variables
    
    return obj;this;
}

new myClassInstance('an A value', 'a B value');

Yes it is.

However, I had to rewrite your code a bit, as the method you're currently using appears to put the function calls into the global scope.

function MyClass(a, b){
    this.a = a;
    this.b = b;
};

function myClassInstance(){
    
    var obj = MyClass.apply(this, arguments);
    console.log(this); //Should show the a and b variables
    
    return obj;
}

new myClassInstance('an A value', 'a B value');

Yes it is.

However, I had to rewrite your code a bit, as the method you're currently using appears to put the function calls into the global scope.

function MyClass(a, b){
    this.a = a;
    this.b = b;
};

function myClassInstance(){
    
    //The apply function will apply MyClass attributes to this object.
    //The apply function itself returns nothing.
    MyClass.apply(this, arguments);
    console.log(this); //Should show the a and b variables
    
    return this;
}

new myClassInstance('an A value', 'a B value');
Source Link

Yes it is.

However, I had to rewrite your code a bit, as the method you're currently using appears to put the function calls into the global scope.

function MyClass(a, b){
    this.a = a;
    this.b = b;
};

function myClassInstance(){
    
    var obj = MyClass.apply(this, arguments);
    console.log(this); //Should show the a and b variables
    
    return obj;
}

new myClassInstance('an A value', 'a B value');