Created
August 31, 2013 16:40
-
-
Save pads/6399323 to your computer and use it in GitHub Desktop.
Learning CoffeeScript the Tiddler way...
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
class Tiddler | |
# @ is shorthand for this.title = title | |
constructor: (@title, @bag) -> | |
# Other properties attached to prototype | |
text: "" | |
tags: [] | |
# toString() function returns properties | |
# Fat arrow ensures 'this' inside the function is always bound to the instance | |
toString: => | |
"#{@title}:#{@bag}" | |
# Static function example | |
@Version: -> | |
"v1.0.0" | |
# Usage | |
tiddler = new Tiddler("About", "pads_public") | |
tiddler.text = "Hello World!" | |
tiddler.tags = [ | |
"one" | |
"two" | |
"three" | |
] | |
console.log "tiddler: #{tiddler.toString()}" | |
console.log "text: #{tiddler.text}" | |
console.log "tag: #{tag}" for tag in tiddler.tags |
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
// Generated by CoffeeScript 1.6.3 | |
(function() { | |
var Tiddler, tag, tiddler, _i, _len, _ref, | |
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | |
Tiddler = (function() { | |
function Tiddler(title, bag) { | |
this.title = title; | |
this.bag = bag; | |
this.toString = __bind(this.toString, this); | |
} | |
Tiddler.prototype.text = ""; | |
Tiddler.prototype.tags = []; | |
Tiddler.prototype.toString = function() { | |
return "" + this.title + ":" + this.bag; | |
}; | |
Tiddler.Version = function() { | |
return "v1.0.0"; | |
}; | |
return Tiddler; | |
})(); | |
tiddler = new Tiddler("About", "pads_public"); | |
tiddler.text = "Hello World!"; | |
tiddler.tags = ["one", "two", "three"]; | |
console.log("tiddler: " + (tiddler.toString())); | |
console.log("text: " + tiddler.text); | |
_ref = tiddler.tags; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
tag = _ref[_i]; | |
console.log("tag: " + tag); | |
} | |
}).call(this); | |
/* | |
//@ sourceMappingURL=Tiddler.map | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment