Created
August 1, 2017 15:09
-
-
Save james-priest/42ea860b1f6ef066bcaaedf5c9bd3094 to your computer and use it in GitHub Desktop.
object literal 2 object literal 2 // source http://jsbin.com/divafuw
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="object literal 2"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>object literal 2</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
/** | |
* Object Literal | |
* https://stackoverflow.com/questions/8219008/call-functions-from-function-inside-an-object-object-literal | |
*/ | |
/** | |
* NOTE: An object literal is only a *declaration*. It will not run the code | |
* behind a function. For that you need to either explicitly call the function | |
* or use an IIFE to Immediately Invoke the Function Expression. | |
* Functions will not run unless called, and a property cannot be assigned the | |
* result of a function unless that function is explicity called (executed) | |
* through code as in the following: | |
*/ | |
var runApp = { | |
init: function () { | |
this.run() | |
}, | |
run: function () { | |
console.log("It's running!"); | |
} | |
}; | |
runApp.init(); | |
// We call init() in order for the code to execute | |
// The other option is to use an IIFE - see global-instance.js | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">/** | |
* Object Literal | |
* https://stackoverflow.com/questions/8219008/call-functions-from-function-inside-an-object-object-literal | |
*/ | |
/** | |
* NOTE: An object literal is only a *declaration*. It will not run the code | |
* behind a function. For that you need to either explicitly call the function | |
* or use an IIFE to Immediately Invoke the Function Expression. | |
* Functions will not run unless called, and a property cannot be assigned the | |
* result of a function unless that function is explicity called (executed) | |
* through code as in the following: | |
*/ | |
var runApp = { | |
init: function () { | |
this.run() | |
}, | |
run: function () { | |
console.log("It's running!"); | |
} | |
}; | |
runApp.init(); | |
// We call init() in order for the code to execute | |
// The other option is to use an IIFE - see global-instance.js | |
</script></body> | |
</html> |
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 Literal | |
* https://stackoverflow.com/questions/8219008/call-functions-from-function-inside-an-object-object-literal | |
*/ | |
/** | |
* NOTE: An object literal is only a *declaration*. It will not run the code | |
* behind a function. For that you need to either explicitly call the function | |
* or use an IIFE to Immediately Invoke the Function Expression. | |
* Functions will not run unless called, and a property cannot be assigned the | |
* result of a function unless that function is explicity called (executed) | |
* through code as in the following: | |
*/ | |
var runApp = { | |
init: function () { | |
this.run() | |
}, | |
run: function () { | |
console.log("It's running!"); | |
} | |
}; | |
runApp.init(); | |
// We call init() in order for the code to execute | |
// The other option is to use an IIFE - see global-instance.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment