Last active
December 9, 2015 15:50
-
-
Save oscarandreu/72b74e402902adfcd882 to your computer and use it in GitHub Desktop.
javascript clean object properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Clear all the elements of an array/object without changing the reference, this must be used in objects binded | |
| * instead of: | |
| * obj = {} | |
| * This assignments change the reference of the object (pointer) because they create a new object, with this method this can be avoided. | |
| */ | |
| $this.clearObject = function(obj){ | |
| var keys = Object.keys(obj); | |
| for (var i = 0; i < keys.length; i++) { | |
| delete obj[keys[i]]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment