Skip to content

Instantly share code, notes, and snippets.

@terraflubb
Created July 27, 2012 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terraflubb/3185739 to your computer and use it in GitHub Desktop.
Save terraflubb/3185739 to your computer and use it in GitHub Desktop.
Abasso#cast in coffeescript
cast = (obj, key = false) ->
o = []
unless isNan obj.length
if !client.ie or client.version > 8
o = Array::slice.call obj
else
utility.iterate obj, (i, idx) ->
o.push i unless idx is "length"
else
if key
o = array.keys obj
else
utility.iterate obj, (i) -> o.push i
o
@avoidwork
Copy link

That's close to what I had cooked up yesterday, but as soon as I try to put that inside an object like below, I get a syntax error

array =
  cast : (obj, key = false) ->  
    o = []
    unless isNan obj.length
    if !client.ie or client.version > 8
      o = Array::slice.call obj
    else
      utility.iterate obj, (i, idx) ->
      o.push i unless idx is "length"
    else
      if key
        o = array.keys obj
      else
        utility.iterate obj, (i) -> o.push i
    o

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