Skip to content

Instantly share code, notes, and snippets.

@katapad
Created March 5, 2013 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katapad/5087870 to your computer and use it in GitHub Desktop.
Save katapad/5087870 to your computer and use it in GitHub Desktop.
Objectをcloneする方法。 prototypeにつっこんでnewとか、jQueryのextendでやるとかあるけど、これが一番シンプルで確実。
clone = (obj)->
return JSON.parse(JSON.stringify(obj))
@katapad
Copy link
Author

katapad commented Mar 5, 2013

コピーできるのはJSONのみ。クラスとかはcloneできない

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment