Last active
December 23, 2015 12:29
-
-
Save nicksheffield/6636043 to your computer and use it in GitHub Desktop.
class in js 1
This file contains hidden or 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
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'; |
This file contains hidden or 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 = { | |
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