Is ‘window’ really global in JavaScript?

The reason why you can access “out of scope” or “free” variables in ECMAScript is the so-called scope chain. The scope chain is a special property from each execution context. As mentioned several times before, a context object looks at least like: [[scope]] Variable / Activation Object “this” context value Each time you access a … Read more

understanding the javascript global namespace and closures

Is there a god (i.e. a parent) object? Yes. More technically, it’s the global object that all these primitives are members of; it just happens that in the browser, the window object is the global object. > window.String === String; true Why is it bad idea to have vars/functions on a global level? Because if … Read more

passing index from for loop to ajax callback function (JavaScript)

You could use a javascript closure: for (var i = 0; i < arr.length; i++) { (function(i) { // do your stuff here })(i); } Or you could just use $.each: var arr = [2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010]; $.each(arr, function(index, value) { $.ajaxSetup({ cache:false }); $.getJSON(“NatGeo.jsp”, { ZipCode: value, … Read more

How to avoid access mutable variable from closure

You need to create a scope to correctly capture tmp_id using a self-executing function. That’s because the entire for loop is one scope, meaning each time through, you’re capturing the same variable. So the callback will end up with the wrong ids, because temp_id‘s value will get changed before the callback is called. I’d ignore … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)