mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
trying out new arrows for function literals -> is a function, => is a bound function
This commit is contained in:
26
test/fixtures/execution/test_functions.coffee
vendored
26
test/fixtures/execution/test_functions.coffee
vendored
@@ -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
|
||||
Reference in New Issue
Block a user