Skip to content

Commit

Permalink
avoid wacking copy.__proto__ in clone()
Browse files Browse the repository at this point in the history
  • Loading branch information
philbudne committed Apr 2, 2021
1 parent de84dd9 commit 22201cc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions spipat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,12 @@ class _PE { // Pattern Element
} // copy

clone() { // clone this element, for copy()
let copy = Object.assign({}, this);

// is this REALLY the best/right way?
// do we need to make a copy of the prototype?????
copy.__proto__ = Object.assign(Object.create(Object.getPrototypeOf(this)),
this);
return copy;
// from https://stackoverflow.com/questions/41474986/how-to-clone-a-javascript-es6-class-instance
// NOTE: works for symbols but not:
// accessor properties (get/set)
// non-enumerable properties (including static methods?)
return Object.assign(Object.create(Object.getPrototypeOf(this)),
this);
}

// Note: this procedure is not used by the normal concatenation circuit,
Expand Down

0 comments on commit 22201cc

Please sign in to comment.