Skip to content

Instantly share code, notes, and snippets.

@ceth-x86
Created April 9, 2013 08:13
Show Gist options
  • Save ceth-x86/5343893 to your computer and use it in GitHub Desktop.
Save ceth-x86/5343893 to your computer and use it in GitHub Desktop.
Javascript : Create simple object
// 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