Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions JavaScript/4-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Object.defineProperty(generateNumbersObject, Symbol.iterator, {
configurable: false
});

// Usage:

console.dir(generateNumbersObject);
console.log(Object.getOwnPropertySymbols(generateNumbersObject));

Expand Down
1 change: 0 additions & 1 deletion JavaScript/6-hide-symbols.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

За что удалил юз стрикт?


// If an ordinary user wants to overwrite a secret field,
// we can not throw error or forbid it,
Expand Down
18 changes: 8 additions & 10 deletions JavaScript/7-hide-symbols-usage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict';

const hideSymbol = require('./7-hide-symbols.js');
const hideSymbol = require('./6-hide-symbols.js');

// we have added an opcional method _debugOutputSecretField,
// to check at the end of the work that the information in the secret field was left
// This is the only way to verify this information
let obj = {
name: 'Marcus Aurelius',
born: 121,
Expand All @@ -10,7 +13,10 @@ let obj = {
get getter() {
return 'GETTER';
},
set setter(value) {}
set setter(value) {},
get _debugOutputSecretField() {
return this[Symbol.for('secret')];
}
};

console.log('\n\nBEFORE PROXYING:\n\n');
Expand Down Expand Up @@ -49,14 +55,6 @@ console.log(obj[Symbol.for('secret')]);
console.log('\x1b[4mconsole.log(Object.entries(obj)):\x1b[0m');
console.log(Object.entries(obj));

// we have added an opcional method _debugOutputSecretField,
// to check at the end of the work that the information in the secret field was left
// This is the only way to verify this information
Object.defineProperty(obj, '_debugOutputSecretField', {
enumerable: false,
get: () => this[Symbol.for('secret')],
configurable: true
});

// proxying:
obj = hideSymbol(obj, Symbol.for('secret'));
Expand Down