Modify constructors to function without new.


Newless is a super-simple JavaScript library that allows you to modify or create constructor functions that don't need to be called with new. This makes your code more safe and allows constructors to be used in more functional contexts (such as

You can use it on a constructor while creating it:

var MyObject = newless(function(something) {
MyObject.prototype.setSomething = function(value) {
  this.something = value;
var instance = MyObject("Hello");
instance.something; // "Hello" 

You can also use it with existing constructors from other libraries without disrupting them:

var Map = newless(google.maps.Map);
var map = Map(document.getElementById("map-canvas"), options);
// or 
var User = newless(Backbone.Model.extend({...}));
var user = User({name: "Jennifer"});

Newless is open source software. It is (c) 2013 Rob Brackett and licensed under the BSD license. The full license text is in the LICENSE file.