1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-02-07 00:31:56 +01:00

Merge pull request #398 from senatori/master

JavaScript tutorial edit
This commit is contained in:
Nami-Doc 2013-11-02 17:05:17 -07:00
commit ed9cd4fb6b

View File

@ -306,8 +306,8 @@ myObj.myOtherFunc = myOtherFunc;
myObj.myOtherFunc(); // = "HELLO WORLD!" myObj.myOtherFunc(); // = "HELLO WORLD!"
// When you call a function with the new keyword, a new object is created, and // 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 // made available to the function via the this keyword. Functions designed to be called
// like this are called constructors. // like that are called constructors.
var MyConstructor = function(){ var MyConstructor = function(){
this.myNumber = 5; this.myNumber = 5;
@ -323,14 +323,14 @@ myNewObj.myNumber; // = 5
// property __proto__. While this is useful for explaining prototypes it's not // 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. // part of the standard; we'll get to standard ways of using prototypes later.
var myObj = { var myObj = {
myString: "Hello world!", myString: "Hello world!"
}; };
var myPrototype = { var myPrototype = {
meaningOfLife: 42, meaningOfLife: 42,
myFunc: function(){ myFunc: function(){
return this.myString.toLowerCase() return this.myString.toLowerCase()
} }
};
myObj.__proto__ = myPrototype; myObj.__proto__ = myPrototype;
myObj.meaningOfLife; // = 42 myObj.meaningOfLife; // = 42