Last active
September 11, 2019 01:45
-
-
Save meidikawardana/3b8a9b0ec9465fab339526378182d739 to your computer and use it in GitHub Desktop.
next gen js - copying by reference & real copy
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | |
var person = { | |
name: 'Max' | |
}; | |
var secondPerson = person; | |
person.name = 'Manu'; | |
console.log(secondPerson); | |
var thirdPerson = { | |
name: 'Max' | |
}; | |
var fourthPerson = _extends({}, thirdPerson); | |
thirdPerson.name = 'Manu'; | |
console.log(fourthPerson); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const person = { | |
name: 'Max' | |
}; | |
const secondPerson = person; | |
person.name = 'Manu'; | |
console.log(secondPerson); | |
const thirdPerson = { | |
name: 'Max' | |
}; | |
const fourthPerson = { | |
...thirdPerson | |
}; | |
thirdPerson.name = 'Manu'; | |
console.log(fourthPerson);</script></body> | |
</html> |
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
'use strict'; | |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | |
var person = { | |
name: 'Max' | |
}; | |
var secondPerson = person; | |
person.name = 'Manu'; | |
console.log(secondPerson); | |
var thirdPerson = { | |
name: 'Max' | |
}; | |
var fourthPerson = _extends({}, thirdPerson); | |
thirdPerson.name = 'Manu'; | |
console.log(fourthPerson); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment