Created
November 6, 2010 10:00
-
-
Save 5v3n/665319 to your computer and use it in GitHub Desktop.
This file contains 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
sys = require 'sys' | |
#oo love: | |
class MyMath | |
square: (x) -> | |
x * x | |
cube: (x) -> | |
this.square(x) * x | |
#functional love: | |
printSquare = (number_to_process) -> | |
"square(#{number_to_process}) = #{myMath.square(number_to_process)}" #<- why does this work? myMath should be out of scope in here! | |
#let's get something rolling: | |
myMath = new MyMath | |
x = 3 | |
#mind the nice string processing: | |
sys.puts printSquare(x) | |
sys.puts "cube(#{x}) = #{myMath.cube(x)}" | |
#what's next - dynamic dispatching ;-)? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, dynamic scoping... if I remember that right, there's a global binding for variables in that. Reminds me of Pascal back then, now I understand.
Wonder if that's an aspect that Crockford discusses in "JS: The good Parts" ;-).
Thanks!