Skip to content

Instantly share code, notes, and snippets.

Created December 10, 2013 15:45
What would you like to do?
A simple .new() method to create instances without constructors. This allow us to rewrite the "new" in order to do other things but create objects.
function $new() {
var obj = Object.create(this);
obj.init.apply(obj, arguments);
return obj;
var SimpleMap = {
new: $new,
init: function() {
this._map = Object.create(null);
get: function(key) {
return this._map[key];
set: function(key, value) {
return this._map[key] = value;
var map =;
Copy link

porque usar Object.create(null) en vez de {} ?

Copy link

Object.create() set's the prototype of the new object to the value you pass to it
{} creates a object which prototype is Object.prototype

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