summaryrefslogtreecommitdiffhomepage
path: root/javascript.html.markdown
diff options
context:
space:
mode:
authorAdam Brenecki <adam@brenecki.id.au>2017-03-01 19:29:32 +1030
committerAdam Brenecki <adam@brenecki.id.au>2017-03-01 19:29:32 +1030
commit54eff5591a1701b40af8632b6c9239dbb8a68ddc (patch)
tree4c9a95da1249cf1b1a5676ec661d326f3b79b1f5 /javascript.html.markdown
parent21652477c23e887a6780d6a9dd97e6e15e1a7a2e (diff)
[javascript/en] Minor changes to formatting, prototype explanations
- Made a comment a complete sentence, to match the style of the rest of the document. - Removed discussion of for/in over Arrays, since it's a can of worms, and for/of is more appropriate if ES6 operators are available. - Reworded introduction to prototypes, and moved it with the rest of the prototype documentation.
Diffstat (limited to 'javascript.html.markdown')
-rw-r--r--javascript.html.markdown28
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.