Created
May 15, 2015 05:58
-
-
Save monochromer/b5405ca60bc233ccf454 to your computer and use it in GitHub Desktop.
Частные члены и прототипы
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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