开发者

Added multiple functions to prototype, but can't call a function from within another for some reason

I did this:

function SomeClass(a) {
  this.a = a;
};

SomeClass.prototype = {

   f1: function() {
     // ...
   },

   f2: function() {

      f1();
   }

};

And I am getting the error:

f1 is not defined

I tried adding 'this.' to the call, but that didn't work either.

WHat could the issue be?

P.S there was a great online javascript book (not this one: http://addyosmani.com/resources/essentialjsdesignpattern开发者_如何学运维s/book/), and it even had a little console window on the bottom of the html page to test things out, any ideas?


How about this?

SomeClass.prototype.f1 = function() {};
SomeClass.prototype.f2 = function() { this.f1(); };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜