As I know, in JavaScript there is no good solution for a private user. The solution described here is inefficient because private members become parts of objects, not prototypes, and therefore require more memory.So, I decided to use the practice of Python - to mark personal material with a leading underscore, letting others know that the makred property or method is not intended to be used externally.But there is a well-known code quality tool, JSLint , and it suggests not using leading or trailing underscores.What is the meaning of this? Is this just a suggestion for code style or underscore can lead to more serious problems? If this is a fair code style convention in the JS community, how strong is it?
JSLint - , , . , . JavaScript /, , . - , , .
JSLint , /, JSLint , . , , , :
/*jslint nomen: true */ var _gaq = {}; /*jslint nomen: false */
, , , - JSLint, "Tolerate... dangling _ in identifiers", .
, , JSHint . , JSLint vs JSHint . JSLint, JSHint .
JavaScript , , . JavaScript, Ben Nadel Nettuts +
. JSHint , /. , , . - . , .
. .
, . . , . POO.
undefined .
Exemple:
function O(){} O.prototype.name = "John"; var o = new O; // o look like that : // { // __proto__: { name: "John"} // } console.log(o.name); // write "John" o.name = "Tom"; // now : // { // name: "Tom", // __poto__: { name: "John" } // } console.log(o.name); // write "Tom"
Defining a name in an instance does not override the prototype value. It is stored only in the instance before the proto value in cascading resolution.
Sorry for my bad english.