Last active
August 16, 2016 18:46
-
-
Save mahemoff/2b334cc1be99c154a44f8867e6b69588 to your computer and use it in GitHub Desktop.
CoffeeScript Object.assign polyfill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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