As a C # programmer, I have a bit of a habit of making things private, which can and should be private, and I always get a weird feeling when the JS type provides me with all its personal parts (and this feeling didn't 'cause'). Let's say I have a type that has a method drawthat internally calls drawBackgroundand drawForegroundthat don't make sense to call on its own. How to implement this?
draw
drawBackground
drawForeground
Option 1
Foo = function(){ this.draw(); }; Foo.prototype.draw = function(){ this.drawBackground(); this.drawForeground(); }; Foo.prototype.drawBackground = function(){}; Foo.prototype.drawForeground = function(){};
Option 2
Foo = (function(){ var constructor = function(){ this.draw(); }; var drawBackground = function(){}; var drawForeground = function(){}; constructor.prototype.draw = function(){ drawBackground.call(this); drawForeground.call(this); }; return constructor; })();
, , , drawBackground drawForeground API, . ? ? , # Javascript, Javascript? .call(this)?
.call(this)
Perl, Camel: " Perl , , , , .". , , , API, . . , , , , , . OO, , , .
, , JavaScript , , .NET, - "prv_" "p_" "_"... , . , , - . , , iffy .