THE AMAZING
THE AMAZING

Reputation: 1593

JS method calling with return

var DOM_N$ = function(selector){
    this.selector = selector;
    return "jello world";
}
DOM_N$.prototype = {
    getSelector: function(){
        return this.selector;
    }
}
function N$(selector){
    return (new DOM_N$(selector));
}

N$('element').selector; //wont return selector because of return
N$('element'); //returns element

I am trying to return the values from an object when no other methods are being called but my return is interrupting my objects methods.

Upvotes: 1

Views: 39

Answers (1)

Guilherme
Guilherme

Reputation: 1990

For DOM_N$ be a constructor, it should returns nothing

var DOM_N$ = function(selector){
    this.selector = selector;
}

Upvotes: 1

Related Questions