Posted By

EvanHahn on 03/12/12


object empty

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Make an empty object in JavaScript

 / Published in: JavaScript

Object.create(null) is a more memory-efficient way to make objects, but it's not supported in all versions of JavaScript, so you can do the "old-fashioned" {} if that function isn't available.

  1. Evan.emptyObject = function() {
  2. if (Object.create) return Object.create(null);
  3. return {};
  4. };

Report this snippet  

You need to login to post a comment.