Skip to content

Instantly share code, notes, and snippets.

@molily
Created February 6, 2016 23:01
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 molily/80bb979b5e69f727f068 to your computer and use it in GitHub Desktop.
Save molily/80bb979b5e69f727f068 to your computer and use it in GitHub Desktop.
# Returns the prototype chain of an object.
# In old browsers, falls back to the __super__ property
# set up by CoffeeScript classes.
# Returns an array.
getPrototypeChain = do ->
if Object.getPrototypeOf
(object) ->
chain = []
while object = Object.getPrototypeOf(object)
chain.push object
chain
else
(object) ->
chain = [object.constructor.prototype]
while object = object.constructor?.__super__
chain.push object
chain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment