Skip to content

Instantly share code, notes, and snippets.

@monochromer
Created May 15, 2015 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monochromer/b5405ca60bc233ccf454 to your computer and use it in GitHub Desktop.
Save monochromer/b5405ca60bc233ccf454 to your computer and use it in GitHub Desktop.
Частные члены и прототипы
function Gadget () {
// частный член
var name ='iPod';
// общедоступная функция
this.getName = function () {
return name;
};
}
Gadget.prototype = (function () {
// частный член
var browser = "Mobile Webkit";
// общедоступные члены прототипа
return {
getBrowser: function () {
return browser;
}
};
}());
var toy = new Gadget();
console.log(toy.getName()); // "собственный" привилегированный метод
console.log(toy.getBrowser()); // привилегированный метод прототипа
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment