Skip to content

Commit e47f27e

Browse files
committed
ES6 private property example with Symbol
1 parent 52d08ce commit e47f27e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

chapter03/01-Stack2.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
let _items = Symbol();
2+
3+
class Stack2 {
4+
5+
constructor () {
6+
this[_items] = [];
7+
}
8+
9+
push(element){
10+
this[_items].push(element);
11+
};
12+
13+
pop(){
14+
return this[_items].pop();
15+
};
16+
17+
peek(){
18+
return this[_items][this[_items].length-1];
19+
};
20+
21+
isEmpty(){
22+
return this[_items].length == 0;
23+
};
24+
25+
size(){
26+
return this[_items].length;
27+
};
28+
29+
clear(){
30+
this[_items] = [];
31+
};
32+
33+
print(){
34+
console.log(this[_items].toString());
35+
};
36+
37+
toString(){
38+
return this[_items].toString();
39+
};
40+
}

0 commit comments

Comments
 (0)