Created
February 5, 2014 00:47
-
-
Save LuisMDeveloper/8815448 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Person is a constructor function. It was written with the intent of being used with the new keyword. */ | |
var Person = function Person(living, age, gender) { | |
// "this" below is the new object that is being created (i.e. this = new Object();) | |
this.living = living; | |
this.age = age; | |
this.gender = gender; | |
this.getGender = function () { return this.gender; }; | |
// When the function is called with the new keyword, "this" is returned instead of false. | |
}; | |
var cody = new Person(true, 22, 'male'); | |
// cody is an object and an instance of Person() | |
console.log(typeof cody); // Logs object. | |
console.log(cody); // Logs the internal properties and values of cody. | |
console.log(cody.constructor); // Logs the Person() function. | |
var myArray = []; // myArray is an instance of Array. | |
// myArray is an object and an instance of the Array() constructor. | |
console.log(typeof myArray); // Logs object! What? Yes, arrays are a type of object. | |
console.log(myArray); // Logs [ ] | |
console.log(myArray.constructor); // Logs Array() | |
console.log(Math.PI);//Static class/object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment