www.YoYoBrain.com - Accelerators for Memory and Learning Questions for Ninja Level Javascript
Category: Default - (94 questions) Javascript: What is catch with using new the behavior varies based on what is put in, Object() constructor versus literal syntax {} literal syntax is consistent Javascript: how to create a constructor var Person = function(name) = {} function that will work withvar me = new Person("Will") Javascript: what does keyword "this" refer an empty object that is created by new and to in constructor syntax:var me = new "this" references it Person("Will");var Person = function(name) { this.name = name;} Javascript: when using new operator to var Person = function(name) - { this.name = create an object what is returned implicitly by name}returns object referenced by "this" creation function if nothing is explicitly variable returned Javascript: drawback to defining functions any time you call new Person() a new when creating objects with new operatorvar function is created in memory Person = function(name) { this.say = function(){}}; Javascript: how to avoid creating new add method to prototype function every time new Person() is called chainPerson.prototype.say = function() {}; with old syntaxvar Person() = function(name) { this.say = function() { }} Javascript: what happens to keyword "this" "this" will point to global object when you leave off new keyword when calling constructorme = Person("will") instead of me = new Person("will") Javascript: side effect in object constructor the link to the prototype is lost, so members if you return another object other than "this" added to it will not be available Javascript: pattern to enforce use of new function Person(name) { if (! (this instanceof operator when creating constructor function Person)) { return new Person(name) }} Javascript: how to find name of function arguments.callee()not allowed in ES5 strict within function mode Javascript: new ECMAScript5 way to detect Array.isArray() if variable is array Javascript: older way to detect if object is object.prototype.toString.call(myVar) === an array "[object Array]" Javascript: how to safely parse JSON JSON.parse() Javascript: how to grab the name of a myFunc.name named functionvar myFunc = function funcName() {}; Javascript: how to create a function that "lazy function definition"var myFunc = does initialization first time then acts function() {// my initializationmyFunc = differently next time function() { //regular code}} Javascript: when using "lazy function the original name is rewritten but the new definition" what happens if function is name will still point to original code. So it will assigned to another variable and run run initialization code every time. Javascript: what is immediate function a function that executes as soon as it is defined(function() {...... }() );or(function() {...} )(); Javascript: what is immediate object uses an object with init() method which is initialization executed immediately after object is created.({ .... init: function() {...}}).init(); Javascript: how to alter what "this" refers to myFunc.apply(context, [params] );"this" will in a function point to context Javascript: calling a function is actually applying a set of arguments ____ to a function Javascript: the process of making a function currying understand and handle partial application is called ____ Javascript: simple way of currying function function add(x,y) { var oldx = x, oldy = y; if add(x,y){...} (typeof oldy === "undefined") { //partial return function(newy) { return oldx + newy; };, } return x + y;} Javascript: use case for currying when you find yourself calling the same function and mostly passing the same parameters, create a curry with redundant parameters Javascript: shortcut to check to see if object var MYAPP = MYAPP || {}; defined or define if missing Javascript: how to create private variables enclose them in a functionvar myobject = in object function () { //private members var name = "can't seee"; return {getname: function() {return name;}}}; Javascript: if you want to use private add to prototypemyObj.prototype = variables in object without creating with (function() {....}()); every new obj() call Javascript: how to turn an object literal into JSON.stringify(object) JSON Javascript: how to throw an error with the argument to throw is an object so it can unique properties have any properties you definethrow {message: "something special, remedy: "special sauce"} Javascript: which can be undefined with implied vars created without var keyword keyword deleteglobal created with var keywordimplied globals created without var keyword Javascript: hoisting behavior when you have scattered var declarations in function , they all act as is the variables are declared at the top of function. Can lead to undefined if you reference before the var declaration in the code Javascript: how should this be for( var i=0, max = myarrays.length, i < max, rewrittenfor(var i=0; i< myarray.length, i++) { i++) { // do something } //do something } Javascript: when using for in to loop how to for (var x in obj) { if (obj.hasOwnProperty(x) { filter for objects own properties (not //do something}} inherited) Javascript: what is wrong with if number begins with "0" it will convert to parseInt("something") octalshould be:parseInt("something", 10); Javascript: how to call a function if all you this["foo"](); have is string with function name Javascript: E4X way to add one xml tag to element1.appendChild( element2 ); another Javascript: E4X way to remove a child node delete element1.elem2 ( elem2 ) from element1 Javascript: E4X what is returned from XML list object element1.bar when there are more than one bar elements Javascript: E4X way to create filter for return place a conditional in parenthesis after the from . or .. selector operatorelement1.foo.(@attribute=="somethi ng") Javascript: E4X way to declare the default default xml namespace="...." namespace Javascript: E4X way to serialize an entire .toXMLString() XML document Javascript: E4X way to grab tag name from .localName QName object Javascript: E4X way to grab namespace .uri from QName object Javascript: E4X way to insert javascript var a = 2;var b =