Skip to content

Instantly share code, notes, and snippets.

@oscarandreu
Last active December 9, 2015 15:50
Show Gist options
  • Select an option

  • Save oscarandreu/72b74e402902adfcd882 to your computer and use it in GitHub Desktop.

Select an option

Save oscarandreu/72b74e402902adfcd882 to your computer and use it in GitHub Desktop.
javascript clean object properties
/**
* 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