Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Last active August 16, 2016 18:46
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 mahemoff/2b334cc1be99c154a44f8867e6b69588 to your computer and use it in GitHub Desktop.
Save mahemoff/2b334cc1be99c154a44f8867e6b69588 to your computer and use it in GitHub Desktop.
CoffeeScript Object.assign polyfill
# adapted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
# with help from JS2Coffee
# https://codepen.io/mahemoff/pen/xOBgdk?editors=0010
if typeof Object.assign != 'function'
Object.assign = (target) ->
index = 1
while index < arguments.length
source = arguments[index]
if source != null
for key of source
if Object::hasOwnProperty.call(source, key)
target[key] = source[key]
index++
target
catalogue = apples: 1, bananas: 2
veges = asparagi: 1, beetroot: 2
Object.assign(catalogue, veges)
console.log catalogue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment