Skip to content

Instantly share code, notes, and snippets.

@nicksheffield
Last active December 23, 2015 12:29
Show Gist options
  • Save nicksheffield/6636043 to your computer and use it in GitHub Desktop.
Save nicksheffield/6636043 to your computer and use it in GitHub Desktop.
class in js 1
function myclass()
{
// property
this.name = 'John';
// method
this.greet = function()
{
console.log('Hello ' + this.name);
}
}
var person = new myclass();
person.greet(); // 'Hello john';
person.name = 'bob';
person.greet(); // 'Hello bob';
person = {
name: 'john',
greet: function(){
console.log('Hello ' + this.name);
}
}
person.greet(); // 'Hello john';
person.name = 'bob';
person.greet(); // 'Hello bob';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment