MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/1j1cw7/coffeescripts_scoping_is_madness/cbas1u3/?context=3
r/programming • u/donatj • Jul 25 '13
315 comments sorted by
View all comments
Show parent comment
2
You can write this in Coffeescript:
class MyClass test: ()-> _private_method() _private_method = () -> console.log "this is a private method"
(note the subtle difference between "_private_method:" and "_private_method ="). Then the compiler will generate:
_private_method:
_private_method =
// Generated by CoffeeScript 1.5.0 var MyClass; MyClass = (function() { var _private_method; function MyClass() {} MyClass.prototype.test = function() { return _private_method(); }; _private_method = function() { return console.log("this is a private method"); }; return MyClass; })();
1 u/drunken_thor Jul 26 '13 Ah! So it does, I just tried it out and it compiled just fine. Why have I not seen this specifie before because that would be a perfect definition of a private method then rather than all these other suggestions I am getting.Thanks for taking the time to teach me something!
1
Ah! So it does, I just tried it out and it compiled just fine. Why have I not seen this specifie before because that would be a perfect definition of a private method then rather than all these other suggestions I am getting.
Thanks for taking the time to teach me something!
View all comments
Show parent comment
2
u/[deleted] Jul 26 '13
You can write this in Coffeescript:
(note the subtle difference between "
_private_method:" and "_private_method ="). Then the compiler will generate: