var funcs = []; // let's create 3 functions for (var i = 0; i < 3; i++) {   // and store them in funcs   funcs[i] = function() {     // each should log its value.     console.log("My value: " + i);   }; } for (var j = 0; j < 3;...
I have a constructor function which registers an event handler:    function MyConstructor(data, transport) {     this.data = data;     transport.on('data', function () {         alert(this.data);     }); }  // Mock transport object var tran...
Given the following examples, why is outerScopeVar undefined in all cases?  var outerScopeVar;  var img = document.createElement('img'); img.onload = function() {     outerScopeVar = this.width; }; img.src = 'lolcat.png'; alert(oute...
I have a nested data structure containing objects and arrays. How can I extract the information, i.e. access a specific or multiple values (or keys)?  For example:  var data = {     code: 42,     items: [{         id: 1,         name: 'foo'...
What are the possible reasons for document.getElementById, $("#id") or any other DOM method / jQuery selector not finding the elements?  Example problems include:   jQuery silently failing to bind an event handler jQuery "getter" me...
I have this code:  <script type="text/javascript">     var foo = 'bar';     <?php         file_put_contents('foo.txt', ' + foo + ');     ?>      var baz = <?php echo 42; ?>;     alert(baz); </scr...
Is there a plugin-less way of retrieving query string values via jQuery (or without)?   If so, how? If not, is there a plugin which can do so?...
I was writing code that does something that looks like:  function getStuffDone(param) {           | function getStuffDone(param) {     var d = Q.defer(); /* or $q.defer */ |     return new Promise(function(resolve, reject) {     // or = new $.Defer...
I'm trying to access a property of an object using a dynamic name. Is this possible?  const something = { bar: "Foobar!" }; const foo = 'bar'; something.foo; // The idea is to access something.bar, getting "Foobar!"...
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?...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.