Created
May 10, 2011 19:03
-
-
Save bostonou/965155 to your computer and use it in GitHub Desktop.
@ gives incorrect reference to "this"
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 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() |
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() { | |
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