Skip to content

Instantly share code, notes, and snippets.

View khaosdoctor's full-sized avatar
💎
Just do things

Lucas Santos khaosdoctor

💎
Just do things
View GitHub Profile
var foo = {
[Symbol()]: 'foo',
[Symbol('foo')]: 'bar',
[Symbol.for('bar')]: 'baz',
propriedade: 'legal'
}
console.log(Symbol.keyFor(Symbol.iterator)) // undefined
let iframe = document.createElement(iframe)
iframe.src = 'https://google.com'
document.body.appendChild(iframe)
console.log(Symbol.iterator === iframe.contentWindow.Symbol.iterator) // True
let texto = '/foo/'
let conversao = /foo/.toString()
console.log(texto.startsWith(conversao)) // True
let texto = '/regex/'
let literal = /regex/
literal[Symbol.match] = false
console.log(text.startsWith(literal)) // True
let iframe = document.createElement('iframe')
iframe.src = 'https://google.com'
document.body.appendChild(iframe)
console.log(Symbol.for('chave') === iframe.contentWindow.Symbol.for('chave')) // True
const s1 = Symbol.for('chave') // Symbol ainda não existe, então ele é criado e retornado
const s2 = Symbol.for('chave') // Symbol já existe então ele é retornado
console.log(Symbol.keyFor(s1)) // Chave
console.log(Symbol.keyFor(s2)) // Chave
const s1 = Symbol.for('chave') // Symbol ainda não existe, então ele é criado e retornado
const s2 = Symbol.for('chave') // Symbol já existe então ele é retornado
// Ao compararmos
console.log(s1 === s2) // True
console.log(Symbol() === Symbol()) // False
console.log(Symbol('abc') === Symbol('abc')) // False
let misterio = Symbol('Uma descrição deste Symbol')