Skip to content

Instantly share code, notes, and snippets.

View shepelevstas's full-sized avatar
😁

Shepelev Stas shepelevstas

😁
  • Russia, Krasnoyarsk
View GitHub Profile
@shepelevstas
shepelevstas / deep_copy.js
Last active August 20, 2022 23:01
deep copy js
// correct object cloning
function clone(obj, fields) {
if (null == obj || "object" != typeof obj) return obj;
if (obj.constructor == File && obj.size)
return obj
var copy = obj.constructor();
if (fields){
for (let i of fields)
if (obj.hasOwnProperty(i))
@shepelevstas
shepelevstas / deep_equal.js
Created August 20, 2022 22:35
deep equal js
function deepEq( x, y, propertyList, pred ) {
if ( x === y ) return true;
// if both x and y are null or undefined and exactly the same
if ( ! ( x instanceof Object ) || ! ( y instanceof Object ) ) return false;
// if they are not strictly equal, they both need to be Objects
if ( x.constructor !== y.constructor ) return false;
// they must have the exact same prototype chain, the closest we can do is
// test there constructor.