خرید بک لینک

Vote count: 1

In a simple browserify app, I'd like to use the this keyword to reference other functions in an exported object, but it doesn't seem to be working as I'd expect it to:

(function() {
  module.exports = {
    a: function() {
      console.log('Hello World');
    },
    b: function() {
      this.a(); // Problem: this is set to window.document
    }
  };
})();

I'd assumed that the above code would work, but it seems that this is set to window.document instead of the exported object. I'm fairly sure I've had this working in the past, so it's probably something simple, but I'm a bit stuck on it!

I'm aware that I could export the object itself to window, or else make it a named variable that can be referenced, but I'd like to understand why the above code doesn't work.

Many thanks!

asked 5 mins ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 5 اسفند 1394 ساعت: 5:29

صفحه بندی