Create a gist now

Instantly share code, notes, and snippets.

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 = SimpleMap.new();

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

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