Skip to content

Instantly share code, notes, and snippets.

@james-priest
Created August 1, 2017 15:09
Show Gist options
  • Save james-priest/42ea860b1f6ef066bcaaedf5c9bd3094 to your computer and use it in GitHub Desktop.
Save james-priest/42ea860b1f6ef066bcaaedf5c9bd3094 to your computer and use it in GitHub Desktop.
object literal 2 object literal 2 // source http://jsbin.com/divafuw
<!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>
/**
* 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