symbol(name)
Last updated
// Create a simple symbol
id = symbol()// Create a symbol for a "private" property
private_data = symbol()
// Create an object with both regular and symbol properties
object user = {
name: "Alice",
age: 25
}
// Add a property using the symbol as the key
user[private_data] = "Sensitive information"
// The symbol property won't show up in regular enumeration
for key in user.getKeys() (
log key // Only outputs "name" and "age"
)
// But can be accessed directly
log user[private_data] // "Sensitive information"