Created
April 9, 2013 08:13
-
-
Save ceth-x86/5343893 to your computer and use it in GitHub Desktop.
Javascript : Create simple object
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
// first method | |
function MyClass() { | |
this.name = "test class"; | |
} | |
var s = new MyClass(); | |
s.name = "some"; | |
// another one method (old-style) | |
var person = new Object(); | |
person.firstName = "John"; | |
person.lastName = "Doe"; | |
person.sayHi = function() { | |
return "Hi there"; | |
} | |
// and another one method (the best) | |
var person = { | |
firstName : "John", | |
lastName : "Doe", | |
sayHi : function() { | |
return "Hi there"; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment