diff options
-rw-r--r-- | javascript.html.markdown | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/javascript.html.markdown b/javascript.html.markdown index 13ed2fb8..a85a7872 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -138,7 +138,7 @@ undefined; // used to indicate a value is not currently present (although // Note that 0 is falsy and "0" is truthy, even though 0 == "0". /////////////////////////////////// -// 2. Variables, Arrays and basics of Objects +// 2. Variables, Arrays and Objects // Variables are declared with the `var` keyword. JavaScript is dynamically // typed, so you don't need to specify type. Assignment uses a single `=` @@ -200,11 +200,6 @@ myObj.myThirdKey = true; // If you try to access a value that's not yet set, you'll get undefined. myObj.myFourthKey; // = undefined -// JavaScript objects are not instantiated from blueprints ("classes" in other -// object-oriented languages), but may refer to another special object called a -// "prototype". See later section for more info. - - /////////////////////////////////// // 3. Logic and Control Structures @@ -253,23 +248,6 @@ for (var x in person){ description += person[x] + " "; } // description = 'Paul Ken 18 ' -// It also works for array objects but iterates over the indices -var myArray = [1, 2, 3, "apple", "banana", function(){}] -for (var index in myArray) { - console.log(index + ": " + myArray[index]); -} -///prints: -// 0: 1 -// 1: 2 -// 2: 3 -// 3: apple -// 4: banana -// 5: function () {} - -// For/in should not be used to iterate over an Array where the index order -// is important, as there is no guarantee that for/in will return the indexes -// in any particular order. - // && is logical and, || is logical or if (house.size == "big" && house.colour == "blue"){ house.contains = "bear"; @@ -456,6 +434,10 @@ var MyConstructor = function(){ myNewObj = new MyConstructor(); // = {myNumber: 5} myNewObj.myNumber; // = 5 +// Unlike most other popular object-oriented languages, JavaScript has no +// concept of 'instances' created from 'class' blueprints; instead, JavaScript +// combines instantiation and inheritance into a single concept: a 'prototype'. + // Every JavaScript object has a 'prototype'. When you go to access a property // on an object that doesn't exist on the actual object, the interpreter will // look at its prototype. |