0
function multiUpload(url, uploder, submit) {
    this.url = url;
    this.browser = uploder;
    this.submit = $(submit);
    self = this;
    multiUpload.prototype.countFile = function (browser) {
        alert(browser);
    }
    this.submit.on("click", this.countFile);
}

The above code not work that defined "browser" undefined than i use

multiUpload.prototype.countFile = function(browser){
    alert(this.browser);
}

it's alert "Object object" and when i passed a "this" keyword to "self" vairable

self = this;
multiUpload.prototype.countFile = function(browser){
    alert(self.browser);
}

now it's work...can any one explain why this happen ???

rrk
  • 14,861
  • 4
  • 25
  • 41
Parth Chavda
  • 1,731
  • 1
  • 18
  • 26

1 Answers1

1

The keyword this is different inside and outside the function call. Inside the call it is equal to whatever object called the function whereas outside the method it is equal to the window object.

MrMadsen
  • 2,035
  • 1
  • 20
  • 28
  • first of all thanx for given reply.like a other language class object properties pass to method from argument ....but when i am trying in javascript it show me object rather than value....can you explain – Parth Chavda Jul 17 '15 at 05:17
  • It is because of scope - see the duplicate question for a detailed response. – MrMadsen Jul 17 '15 at 05:25