Jon W
Jon W

Reputation: 39

.prototype not allowed in function closures?

JS = {
    xml : function() {
        if(window.XMLHttpRequest) {
        this.http = new window.XMLHttpRequest();
        }

    },

    xml.prototype.ajax : function() {
        alert(this.http);
    }
}

returns Uncaught SyntaxError: Unexpected token .

Upvotes: 0

Views: 22

Answers (1)

josh.bradley
josh.bradley

Reputation: 79

This isn't a closure its an object declaration. You can't access the xml property inside the JS object. You would have to do this.

JS = {
xml : function() {
    if(window.XMLHttpRequest) {
    this.http = new window.XMLHttpRequest();
    }

},
}

JS.xml.prototype.ajax = function() {
    alert(this.http);
}

Upvotes: 1

Related Questions