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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
62
Other Decks in Technology
See All in Technology
学生・新卒・ジュニアから目指すSRE
hiroyaonoe
2
580
IaaS/SaaS管理における SREの実践 - SRE Kaigi 2026
bbqallstars
4
1.8k
Agile Leadership Summit Keynote 2026
m_seki
1
570
CDK対応したAWS DevOps Agentを試そう_20260201
masakiokuda
1
230
StrandsとNeptuneを使ってナレッジグラフを構築する
yakumo
1
100
2026年、サーバーレスの現在地 -「制約と戦う技術」から「当たり前の実行基盤」へ- /serverless2026
slsops
2
220
Kiro IDEのドキュメントを全部読んだので地味だけどちょっと嬉しい機能を紹介する
khmoryz
0
170
OWASP Top 10:2025 リリースと 少しの日本語化にまつわる裏話
okdt
PRO
3
590
Greatest Disaster Hits in Web Performance
guaca
0
190
【Oracle Cloud ウェビナー】[Oracle AI Database + AWS] Oracle Database@AWSで広がるクラウドの新たな選択肢とAI時代のデータ戦略
oracle4engineer
PRO
1
120
Data Hubグループ 紹介資料
sansan33
PRO
0
2.7k
FinTech SREのAWSサービス活用/Leveraging AWS Services in FinTech SRE
maaaato
0
130
Featured
See All Featured
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
220
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
51
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
The Curious Case for Waylosing
cassininazir
0
230
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
930
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Spectacular Lies of Maps
axbom
PRO
1
520
My Coaching Mixtape
mlcsv
0
47
RailsConf 2023
tenderlove
30
1.3k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
730
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