var Treasure = function(){
function locate(){
return this.x * this.y + 31337;
}
function Treasure(x, y){
this.x = x;
this.y = y;
}
Treasure.prototype.find = function find(){
return locate.call(this);
};
return Treasure;
}();
locate- a common private function for constructor and prototype methods. Using call, he can act as a method and use this.
A more complete implementation of this concept is interface objects and implementation objects. Instead of having a few random functions-like-methods (similar to the location above), you actually create an entire class that is private. Each external interface creation creates two objects: an open shell interface and a private implementation object. This allows you to publish an interface that provides another, possibly easy-to-use API. Or it may allow you to reuse individual private implementation objects for entire groups of interface objects.
, DOM ( js, ). (, node), , , . , , .
Dom.js - DOM, js. , , . IDL: API , . , , , : https://github.com/Benvie/svgstuff/blob/master/lib/defs.js
user748221