0

I have an onPaste event. I am trying to deep copy it using the standard methods, e.g.

_.cloneDeep(pasteEvent)

or

Object.assign({}, pasteEvent)

or

JSON.parse(JSON.stringify(pasteEvent))

It returns as empty object (lodash) or an object with one property (the other two methods). The event that I can't copy:

enter image description here

VSO
  • 11,546
  • 25
  • 99
  • 187
  • 1
    What problem you're solving that requires a deep clone of a host object? – zerkms Nov 28 '16 at 21:38
  • Both `Object.assign` and `JSON.stringify` will only visit *own* properties that are *enumerable*. –  Nov 28 '16 at 21:38
  • @zerkms: I am trying to cancel and re-issue a paste event, with changed paste content. See here: http://stackoverflow.com/questions/40848003/set-preventdefault-back-to-false-on-javascript-event I later found out that I CANNOT create a clipboard event in Chrome (can find source if interested). So I have to resort to copying an existing event. Ideally, I would just change some props, but they are immutable. The root of the problem is that I need to "preventDefault" on the original event, but I need the event I reissue to have preventDefault: false; – VSO Nov 28 '16 at 21:40
  • 1
    "I later found out that I CANNOT create a clipboard event" --- does not this automatically mean you cannot deep-clone it? If you cannot create something -> you cannot clone it. – zerkms Nov 28 '16 at 21:43
  • @zerkms I don't get this. I thought everything, including events, was "just an object." I understand a constructor not being provided, but not being able to clone an object is weird. – VSO Nov 28 '16 at 23:37

0 Answers0