1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/scope.coffee
2011-08-01 17:28:52 -04:00

34 lines
739 B
CoffeeScript

# Scope
# -----
# * Variable Safety
# * Variable Shadowing
# * Auto-closure (`do`)
# * Global Scope Leaks
test "reference `arguments` inside of functions", ->
sumOfArgs = ->
sum = (a,b) -> a + b
sum = 0
sum += num for num in arguments
sum
eq 10, sumOfArgs(0, 1, 2, 3, 4)
test "assignment to an Object.prototype-named variable should not leak to outer scope", ->
# FIXME: fails on IE
(->
constructor = 'word'
)()
ok constructor isnt 'word'
test "siblings of splat parameters shouldn't leak to surrounding scope", ->
x = 10
oops = (x, args...) ->
oops(20, 1, 2, 3)
eq x, 10
test "catch statements should introduce their argument to scope", ->
try throw ''
catch e
do -> e = 5
eq 5, e