Private vs Public Javascript Functions -
can please explain difference between these 2 functions?
(function(engine, $, undefined) { //hidden scope //public function below engine.init = function() { console.log("im public"); } //anonymous functions below function login() { console.log("im private"); } })( window.engine = window.engine || {}, jquery );
specifically, i'd know why engine.init()
available in console
login
isn't.
init
property of engine
object refers function.
can access other property.
login
local variable within anonymous, "immediately invoked function expression" (iife); other local variables, name visible within declaring function
Comments
Post a Comment