Skip to content

Instantly share code, notes, and snippets.

@5v3n
Created November 6, 2010 10:00
Show Gist options
  • Save 5v3n/665319 to your computer and use it in GitHub Desktop.
Save 5v3n/665319 to your computer and use it in GitHub Desktop.
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 ;-)?
@5v3n
Copy link
Author

5v3n commented Nov 6, 2010

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment