What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined globally?...
I have restructured my code to promises, and built a wonderful long flat promise chain, consisting of multiple .then() callbacks. In the end I want to return some composite value, and need to access multiple intermediate promise results. However th...
Using instance methods as callbacks for event handlers changes the scope of this from "My instance" to "Whatever just called the callback". So my code looks like this  function MyObject() {   this.doSomething = function() {     ......
A friend of mine and I are currently discussing what is a closure in JS and what isn't. We just want to make sure we really understand it correctly.  Let's take this example. We have a counting loop and want to print the counter variable on...
Stylistically, I prefer this structure:  var Filter = function( category, value ){   this.category = category;   this.value = value;    // product is a JSON object   Filter.prototype.checkProduct = function( product ){     // run some checks     re...
I was facing an issue while developing this small userscript. When I wanted to block every XMLHttpRequest from the running website with my script, nothing was happening (at least with Chrome):  function main() {   // Override XHR.open with a custom...
I'm reading the backbone.js documents and seeing a lot of code that assigns attributes to the window object:  window.something = "whatever";   what's the difference between calling this code, and just assigning the variable and crea...
Just a quick question about the scoping of JavaScript variables.  Why does the alert() function print the value of i instead of returning undefined?  $(document).ready(function () {     for(var i = 0; i < 10; i += 1){     }       alert("What...
Take this piece of Javascript in a browser:  <script>  console.log(window.someThing); var x = 12;  function foo() {    window.otherThing = x; }  </script>   Inside foo we can access window, we all know that, but why exactly?   Is it som...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.