Skip to content

Instantly share code, notes, and snippets.

@KinoAR
Last active October 31, 2016 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KinoAR/c1774808f3a442a47c647e175bd1c13b to your computer and use it in GitHub Desktop.
Save KinoAR/c1774808f3a442a47c647e175bd1c13b to your computer and use it in GitHub Desktop.
A gist for my symbols tutorial for RPGMaker MV
//=============================================================================
// Symbols
//=============================================================================
//Creating Local Symbol
var localSymbol = Symbol("My Symbol");
//Creating Global Symbol
var mySymbol2 = Symbol.for("My Symbol2");
//Getting and storing a global symbol
var mySymbol2dup = Symbol.for("My Symbol2");
//Check if local symbol is equal to global symbol
let testString = `Are localSymbol and mySymbol2 the same? : ${localSymbol === mySymbol2}`;
console.log(testString);//Are localSymbol and mySymbol2 the same? :false
//Check if duplilcate is equal to global symbol
testString = `Are mySymbol2 and mySymbol2dup the same? : ${mySymbol2 === mySymbol2dup}`;
console.log(testString);//Are mySymbol2 and mySymbol2dup the same? : true
//Check for symbols in global symbol registry
console.log(`Local Symbol key: ${Symbol.keyFor(localSymbol)}`); // Local Symbol key: Undefined
console.log(`Global Symbol key: ${Symbol.keyFor(mySymbol2)}`); //Global Symbol key: My Symbol2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment