From e546f9cd9c87733fc9e502746109a8abe0a12f86 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 2 Sep 2013 21:33:53 -0700 Subject: Add file download to javascript.js --- javascript.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index 1dd6e2be..bc2a973a 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -1,7 +1,8 @@ --- language: javascript -author: Adam Brenecki -author_url: http://adam.brenecki.id.au +contributors: + - ["Adam Brenecki", "http://adam.brenecki.id.au"] +filename: javascript.js --- Javascript was created by Netscape's Brendan Eich in 1995. It was originally -- cgit v1.2.3 From 3f9ba06563c580c4795228a822475bf305d5b694 Mon Sep 17 00:00:00 2001 From: jeroenransijn Date: Wed, 11 Sep 2013 15:51:21 +0200 Subject: Note aboute setTimeout --- javascript.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index bc2a973a..859d61a9 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -219,6 +219,7 @@ function myFunction(){ // this code will be called in 5 seconds' time } setTimeout(myFunction, 5000); +// Note: setTimeout isn't part of the JS language, but is provided by browsers and Node.js. // Function objects don't even have to be declared with a name - you can write // an anonymous function definition directly into the arguments of another. -- cgit v1.2.3 From 9d1015232c1c5cf90ccc8d4807d8c4216a2406dc Mon Sep 17 00:00:00 2001 From: Adam Brenecki Date: Fri, 13 Sep 2013 20:21:14 +0930 Subject: Wrapped setTimeout note to 80 chars --- javascript.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index 859d61a9..2f742574 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -219,7 +219,8 @@ function myFunction(){ // this code will be called in 5 seconds' time } setTimeout(myFunction, 5000); -// Note: setTimeout isn't part of the JS language, but is provided by browsers and Node.js. +// Note: setTimeout isn't part of the JS language, but is provided by browsers +// and Node.js. // Function objects don't even have to be declared with a name - you can write // an anonymous function definition directly into the arguments of another. -- cgit v1.2.3 From 49b30c38e2741162bd1661e020fe80c80759dee3 Mon Sep 17 00:00:00 2001 From: Adam Brenecki Date: Fri, 20 Sep 2013 19:17:10 +0930 Subject: Add missing semicolon --- javascript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index 2f742574..9adc0a6d 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -359,7 +359,7 @@ myObj.meaningOfLife; // = 43 // are given when they're created with that constructor and the new keyword. myConstructor.prototype = { getMyNumber: function(){ - return this.myNumber + return this.myNumber; } }; var myNewObj2 = new myConstructor(); -- cgit v1.2.3 From 750b2a2f21262fc011d5ee07362c667223d3de23 Mon Sep 17 00:00:00 2001 From: Adam Brenecki Date: Fri, 20 Sep 2013 19:22:00 +0930 Subject: [javascript] clarify constructor prototype example, as per #204 --- javascript.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index 9adc0a6d..b15eae7c 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -358,12 +358,15 @@ myObj.meaningOfLife; // = 43 // the constructor function itself; instead, it's the prototype that new objects // are given when they're created with that constructor and the new keyword. myConstructor.prototype = { + myNumber: 5, getMyNumber: function(){ return this.myNumber; } }; var myNewObj2 = new myConstructor(); myNewObj2.getMyNumber(); // = 5 +myNewObj2.myNumber = 6 +myNewObj2.getMyNumber(); // = 6 // Built-in types like strings and numbers also have constructors that create // equivalent wrapper objects. -- cgit v1.2.3 From a91b4fd300d0fc66b5d5d9c29d86d8b4c4cb5464 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Thu, 3 Oct 2013 20:02:16 +0200 Subject: be consistent with PascalCasing of constructors --- javascript.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index b15eae7c..6b6be34d 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -357,13 +357,13 @@ myObj.meaningOfLife; // = 43 // Constructors have a property called prototype. This is *not* the prototype of // the constructor function itself; instead, it's the prototype that new objects // are given when they're created with that constructor and the new keyword. -myConstructor.prototype = { +MyConstructor.prototype = { myNumber: 5, getMyNumber: function(){ return this.myNumber; } }; -var myNewObj2 = new myConstructor(); +var myNewObj2 = new MyConstructor(); myNewObj2.getMyNumber(); // = 5 myNewObj2.myNumber = 6 myNewObj2.getMyNumber(); // = 6 -- cgit v1.2.3 From 9c0e7c548d3fb0cf655f282e36b1c24b21bba83b Mon Sep 17 00:00:00 2001 From: Adam Brenecki Date: Thu, 10 Oct 2013 08:33:39 +1030 Subject: [javascript] Add bit about array mutability. Closes #381. --- javascript.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index 6b6be34d..97c5b712 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -142,6 +142,10 @@ var myArray = ["Hello", 45, true]; // Array indices start at zero. myArray[1]; // = 45 +// Arrays are mutable and of variable length. +myArray.push("World"); +myArray.length; // = 4 + // JavaScript's objects are equivalent to 'dictionaries' or 'maps' in other // languages: an unordered collection of key-value pairs. var myObj = {key1: "Hello", key2: "World"}; -- cgit v1.2.3 From c149c619da0f258c55bfb355e9d9e3b02dc880c2 Mon Sep 17 00:00:00 2001 From: Adam Brenecki Date: Thu, 10 Oct 2013 10:52:56 +1030 Subject: [javascript] Added note about ints --- javascript.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index 97c5b712..2ac98105 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -38,6 +38,8 @@ doStuff() // 1. Numbers, Strings and Operators // Javascript has one number type (which is a 64-bit IEEE 754 double). +// As with Lua, don't freak out about the lack of ints: doubles have a 52-bit +// mantissa, which is enough to store integers up to about 9✕10¹⁵ precisely. 3; // = 3 1.5; // = 1.5 -- cgit v1.2.3 From cba64739f5e61f8fb524dc1cc88cbb31920d2b86 Mon Sep 17 00:00:00 2001 From: Steven Senatori Date: Sat, 2 Nov 2013 16:50:29 -0700 Subject: Deleted some bad syntax and tweaked an explanation for clarity --- javascript.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index 2ac98105..36aad102 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -306,8 +306,8 @@ myObj.myOtherFunc = myOtherFunc; myObj.myOtherFunc(); // = "HELLO WORLD!" // When you call a function with the new keyword, a new object is created, and -// made available to the function via this. Functions designed to be called -// like this are called constructors. +// made available to the function via the this keyword. Functions designed to be called +// like that are called constructors. var MyConstructor = function(){ this.myNumber = 5; @@ -323,14 +323,14 @@ myNewObj.myNumber; // = 5 // property __proto__. While this is useful for explaining prototypes it's not // part of the standard; we'll get to standard ways of using prototypes later. var myObj = { - myString: "Hello world!", + myString: "Hello world!" }; var myPrototype = { meaningOfLife: 42, myFunc: function(){ return this.myString.toLowerCase() } -}; + myObj.__proto__ = myPrototype; myObj.meaningOfLife; // = 42 -- cgit v1.2.3 From 34b0264620c540bcdc451c96996ff5a38a6d26db Mon Sep 17 00:00:00 2001 From: Steven Senatori Date: Sat, 2 Nov 2013 17:30:36 -0700 Subject: fixing one of my corrections, no idea why I delted the }; on line 333 previously...sorry --- javascript.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index 36aad102..2d665e67 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -330,6 +330,7 @@ var myPrototype = { myFunc: function(){ return this.myString.toLowerCase() } +}; myObj.__proto__ = myPrototype; myObj.meaningOfLife; // = 42 -- cgit v1.2.3 From 9f0ae279d83a41bec3c9998c5245c46908942873 Mon Sep 17 00:00:00 2001 From: Adam Brenecki Date: Tue, 5 Nov 2013 12:47:58 +1030 Subject: [javascript/en] Enforce 80-char line width --- javascript.html.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index 2d665e67..b6d4c8b7 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -107,10 +107,10 @@ false; // There's also null and undefined null; // used to indicate a deliberate non-value -undefined; // used to indicate a value is not currently present (although undefined - // is actually a value itself) +undefined; // used to indicate a value is not currently present (although + // undefined is actually a value itself) -// false, null, undefined, NaN, 0 and "" are falsy, and everything else is truthy. +// false, null, undefined, NaN, 0 and "" are falsy; everything else is truthy. // Note that 0 is falsy and "0" is truthy, even though 0 == "0". /////////////////////////////////// @@ -306,8 +306,8 @@ myObj.myOtherFunc = myOtherFunc; myObj.myOtherFunc(); // = "HELLO WORLD!" // When you call a function with the new keyword, a new object is created, and -// made available to the function via the this keyword. Functions designed to be called -// like that are called constructors. +// made available to the function via the this keyword. Functions designed to be +// called like that are called constructors. var MyConstructor = function(){ this.myNumber = 5; -- cgit v1.2.3