Skip to content

Instantly share code, notes, and snippets.

@jacobbubu
Created October 19, 2016 08:54
Show Gist options
  • Save jacobbubu/1fda3e6adec6dfeeba72a773a9ca0cf3 to your computer and use it in GitHub Desktop.
Save jacobbubu/1fda3e6adec6dfeeba72a773a9ca0cf3 to your computer and use it in GitHub Desktop.
Object.assign
assign = (target, firstSource) ->
if !target?
throw new TypeError('Cannot convert first argument to object')
to = Object(target)
hasPendingException = false
pendingException = undefined
i = 1
while i < arguments.length
nextSource = arguments[i]
if !nextSource?
i++
continue
keysArray = Object.keys Object(nextSource)
nextIndex = 0
len = keysArray.length
while nextIndex < len
nextKey = keysArray[nextIndex]
try
desc = Object.getOwnPropertyDescriptor(nextSource, nextKey)
if desc != undefined and desc.enumerable
to[nextKey] = nextSource[nextKey]
catch e
if !hasPendingException
hasPendingException = true
pendingException = e
nextIndex++
throw pendingException if hasPendingException
i++
to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment