Created
July 1, 2020 06:27
-
-
Save Hoxtygen/4ba041f741c62483050f356e39f1c8b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object literals | |
let myObjectLiteral = { | |
variableKey: "variableValue", | |
functionKey: function (params) { | |
// magic goes in here | |
}, | |
}; | |
// module defined with object literal | |
var myModule = { | |
myProperty: "someValue", | |
//object literals can contain properties and methods. | |
//here, anothere object is defined for configuration purposes | |
myConfig: { | |
useCaching: true, | |
language: "en", | |
}, | |
//a very basic method | |
myMethod: function () { | |
console.log("I can have something?"); | |
}, | |
//output a value based on current configuration | |
myMethod2: () => { | |
console.log( | |
"Caching is" + (this.myConfig.useCaching) ? "enabled" : "disabled" | |
); | |
}, | |
//override the current configuration | |
myMethod3: (newConfig) => { | |
if (typeof newConfig === "object") { | |
this.myConfig = newConfig; | |
console.log(this.myConfig.language); | |
} | |
}, | |
}; | |
myModule.myMethod(); | |
myModule.myMethod2();// undefined. | |
myModule.myMethod3({ | |
language: "fr", | |
useCaching: false | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment