trying out new arrows for function literals -> is a function, => is a bound function

This commit is contained in:
Jeremy Ashkenas
2010-01-26 10:52:05 -05:00
parent 55df898112
commit a9f016e292
54 changed files with 259 additions and 259 deletions

View File

@@ -1,6 +1,6 @@
x: 1
y: {}
y.x: => 3
y.x: -> 3
print x is 1
print typeof(y.x) is 'function'
@@ -9,17 +9,17 @@ print y.x.name is 'x'
# The empty function should not cause a syntax error.
=>
->
obj: {
name: "Fred"
bound: =>
(==> print(this.name is "Fred"))()
bound: ->
(=> print(this.name is "Fred"))()
unbound: =>
(=> print(!this.name?))()
unbound: ->
(-> print(!this.name?))()
}
obj.unbound()
@@ -29,18 +29,18 @@ obj.bound()
# The named function should be cleared out before a call occurs:
# Python decorator style wrapper that memoizes any function
memoize: (fn) =>
memoize: (fn) ->
cache: {}
self: this
(args...) =>
(args...) ->
key: args.toString()
return cache[key] if cache[key]
cache[key] = fn.apply(self, args)
Math: {
Add: (a, b) => a + b
AnonymousAdd: ((a, b) => a + b)
FastAdd: memoize (a, b) => a + b
Add: (a, b) -> a + b
AnonymousAdd: ((a, b) -> a + b)
FastAdd: memoize (a, b) -> a + b
}
print Math.Add(5, 5) is 10
@@ -53,5 +53,5 @@ print 100 > 1 if 1 > 0
print true unless false
print true for i in [1..3]
print_func: (f) => print(f())
print_func => true
print_func: (f) -> print(f())
print_func -> true