add `var self = this;` before function