Skip to content

Instantly share code, notes, and snippets.

@douglaspetrin
Created November 2, 2018 13:55
Show Gist options
  • Save douglaspetrin/c8c88723e7f0bd998dcf4c65ccd894dc to your computer and use it in GitHub Desktop.
Save douglaspetrin/c8c88723e7f0bd998dcf4c65ccd894dc to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/padotix
<!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">
// Reference and Primitive Types Refresher
/* numbers, strings, boleans -> Primitive Types */
'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 number = 1;
var num2 = number;
console.log(num2);
/* Objects and arrays -> Reference Types */
var person = {
name: 'Doug'
};
var secondPerson = person;
person.name = 'Jason';
console.log(secondPerson);
/* just copying the pointer and not the object */
var animal = {
name: 'Dog'
};
var secondAnimal = _extends({}, animal);
animal.name = 'Pit';
console.log(secondAnimal);
/* now it is copying the object even if we have 'Pit' */
/* to copy the properties of an object we have to use {}, otherwise
we'll just copy the pointer
*/
</script>
<script id="jsbin-source-javascript" type="text/javascript">// Reference and Primitive Types Refresher
/* numbers, strings, boleans -> Primitive Types */
const number = 1;
const num2 = number;
console.log(num2);
/* Objects and arrays -> Reference Types */
const person = {
name: 'Doug'
};
const secondPerson = person;
person.name = 'Jason';
console.log(secondPerson);
/* just copying the pointer and not the object */
const animal = {
name: 'Dog'
};
const secondAnimal = {
...animal
};
animal.name = 'Pit';
console.log(secondAnimal);
/* now it is copying the object even if we have 'Pit' */
/* to copy the properties of an object we have to use {}, otherwise
we'll just copy the pointer
*/</script></body>
</html>
// Reference and Primitive Types Refresher
/* numbers, strings, boleans -> Primitive Types */
'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 number = 1;
var num2 = number;
console.log(num2);
/* Objects and arrays -> Reference Types */
var person = {
name: 'Doug'
};
var secondPerson = person;
person.name = 'Jason';
console.log(secondPerson);
/* just copying the pointer and not the object */
var animal = {
name: 'Dog'
};
var secondAnimal = _extends({}, animal);
animal.name = 'Pit';
console.log(secondAnimal);
/* now it is copying the object even if we have 'Pit' */
/* to copy the properties of an object we have to use {}, otherwise
we'll just copy the pointer
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment