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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -