Skip to content

Instantly share code, notes, and snippets.

@bostonou
Created May 10, 2011 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bostonou/965155 to your computer and use it in GitHub Desktop.
Save bostonou/965155 to your computer and use it in GitHub Desktop.
@ gives incorrect reference to "this"
class Test
constructor: ->
Test.count = 2
@count: 0
@show: ->
console.log "Count = #{@count}"
console.log ('Not printed' for i in [1..@count]).join(" ")
new Test
Test.show()
(function() {
var Test;
Test = (function() {
function Test() {
Test.count = 2;
}
Test.count = 0;
Test.show = function() {
var i;
console.log("Count = " + this.count);
return console.log(((function() {
var _ref, _results;
_results = [];
for (i = 1, _ref = this.count; 1 <= _ref ? i <= _ref : i >= _ref; 1 <= _ref ? i++ : i--) {
_results.push('Not printed');
}
return _results;
})()).join(" "));
};
return Test;
})();
new Test;
Test.show();
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment