Created
February 10, 2015 19:04
-
-
Save mayfer/1bb2062374df565b286b to your computer and use it in GitHub Desktop.
Example showing methods within instances of functions, via the "this" keyword. Also, chaining methods by returning "this" every time.
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
<html> | |
<head> | |
<style> | |
body { background: #358; color: #fff; padding: 50px; font-family: sans-serif; } | |
</style> | |
</head> | |
<body> | |
<script> | |
var methodyObject = function() { | |
this.my_method = function() { | |
console.log("YAY a method"); | |
return this; | |
} | |
this.other_method = function() { | |
console.log("omg YAY other"); | |
} | |
} | |
var obj = new methodyObject(); | |
var result = obj.my_method().other_method(); | |
console.log(result); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment