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
49
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Hyper Private Variables in Javascript
Or, a merry romp through the fields of "why are javascript objects kinda weird"?
Ben Green
May 16, 2013
More Decks by Ben Green
See All by Ben Green
Lessons Learned with Grunt and Jasmine
veganben
0
65
Other Decks in Technology
See All in Technology
え?フロントエンドエンジニアの ワイがインフラも!?
puku0x
1
400
Pavlokで始める電撃駆動開発
sgrsn
0
170
Retriever と Reranker、結局どうする?
kazuaki
3
700
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.2k
Agent 時代の Kaggle 展望 / kaggle-in-the-agentic-era
upura
1
640
AI ネイティブな組織に Gemini Enterprise Agent Platform がなぜ必要なのか
asei
1
190
AI時代の強いチームの作り方
yuukiyo
25
16k
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
53k
社内の7割が使うデータ基盤を、 データチーム2人で回すためにやったこと
koh_yoshi
4
1k
Bill One 開発エンジニア 紹介資料
sansan33
PRO
7
19k
第3回しろおびセキュリティスポンサーセッション
log0417
0
150
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
22k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Building the Perfect Custom Keyboard
takai
2
830
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
430
It's Worth the Effort
3n
188
29k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
390
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
480
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
400
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
460
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
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