Skip to content

Commit ba5c836

Browse files
committed
Tentando ter atribuitos privados no javascript: underscore e symbol
1 parent cd029d3 commit ba5c836

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const Stack = require("../../src/js/data-structures/stack-symbol");
2+
3+
const stack = new Stack();
4+
5+
stack.push(5);
6+
stack.push(6);
7+
stack.push(7);
8+
9+
console.log(stack.peek());
10+
console.log(stack);
11+
12+
let objectSymbols = Object.getOwnPropertySymbols(stack);
13+
console.log("size:", objectSymbols.length);
14+
console.log("obj", objectSymbols);
15+
console.log("push", stack[objectSymbols[0]].push(10));
16+
17+
stack[objectSymbols[0]][0] = "joao";
18+
console.log(stack[objectSymbols[0]]);

examples/charpter04/stack.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ stack.push(6);
77
stack.push(7);
88

99
console.log("Stack: ", stack.isEmpty());
10-
1110
console.log("Stack: ", stack.toString());
11+
12+
console.log(Object.getOwnPropertyNames(stack));
13+
console.log(Object.keys(stack));
14+
console.log(stack.items);
15+
console.log(stack.count);

0 commit comments

Comments
 (0)