Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Hyper Private Variables in Javascript
Search
Ben Green
May 16, 2013
Technology
0
45
Hyper Private Variables in Javascript
Or, a merry romp through the fields of "why are javascript objects kinda weird"?
Ben Green
May 16, 2013
Tweet
Share
More Decks by Ben Green
See All by Ben Green
Lessons Learned with Grunt and Jasmine
veganben
0
61
Other Decks in Technology
See All in Technology
LLM時代にデータエンジニアの役割はどう変わるか?
ikkimiyazaki
6
1.1k
三菱電機・ソニーグループ共同の「Agile Japan企業内サテライト」_2025
sony
0
110
「Verify with Wallet API」を アプリに導入するために
hinakko
1
260
能登半島災害現場エンジニアクロストーク 【JAWS FESTA 2025 in 金沢】
ditccsugii
0
180
E2Eテスト設計_自動化のリアル___Playwrightでの実践とMCPの試み__AIによるテスト観点作成_.pdf
findy_eventslides
1
550
OpenAI gpt-oss ファインチューニング入門
kmotohas
2
1.1k
小学4年生夏休みの自由研究「ぼくと Copilot エージェント」
taichinakamura
0
550
Why Governance Matters: The Key to Reducing Risk Without Slowing Down
sarahjwells
0
120
extension 現場で使えるXcodeショートカット一覧
ktombow
0
220
M5製品で作るポン置きセルラー対応カメラ
sayacom
0
170
カンファレンスに託児サポートがあるということ / Having Childcare Support at Conferences
nobu09
1
460
AI時代だからこそ考える、僕らが本当につくりたいスクラムチーム / A Scrum Team we really want to create in this AI era
takaking22
7
4k
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
56
14k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Designing for humans not robots
tammielis
254
26k
Six Lessons from altMBA
skipperchong
28
4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.7k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
900
The Power of CSS Pseudo Elements
geoffreycrofte
79
6k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
Statistics for Hackers
jakevdp
799
220k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Transcript
Hyper-Private Variables in JavaScript @veganben
None
Netscape Naviagtor Asynchronous Prototype based Influenced by C, Self, Scheme
An evolving langauge TC 39 JS Lint & JSON Coffee
Script
Patterns
Objects
Getting Started:
Array.prototype.last = function(){ return this[this.length-1] } var theEnd = [1,2,3,4,5].last();
>> 5
Object.defineProperty(Array.prototype, 'last', { enumerable: false, configurable: true, get: function() {
return this[this.length - 1]; }, set: undefined });
Constructor: function Message(param) { this.greeting = param; } Instantiation: var
helloMessage = new Message('hello');
prototype inheritance: Message.prototype.greet = function (who) { return this.greeting +
" " + who; } method invocation: var greeting = helloMessage.greet("world"); >> “hello world” function Message(param) { this.greeting = param; } var sayHello = new Message('hello');
Public and Private:
function Message(param) { var greetedCount = 0; this.greeeting = param;
}
function Message(param) { var greetedCount = 0; this.incrementGreeted = function(){
greetedCount++; } this.greeeting = param; }
var myModule = (function () { var privateStuff; var publicStuff;
return { visible: publicStuff }
function Counter() { var increment, decrement, get; (function() { var
privateCount = 0; increment = function() { return count++ }; decrement = function() { return count--; }; get = function() { return privateCount; }; })(); this.set = function(param) { if(param >=0 ){ increment(); } else { decrement } }; this.getCount = function() { return get(); } }
var filmCount = new Count(); filmCount.set(1); filmCount.getCount();
for example