From 5f2f04c4ca42d4e5b2ab6dcf0571adb6327cf5b1 2013-10-23 02:41:06 From: MinRK Date: 2013-10-23 02:41:06 Subject: [PATCH] add utils.always_new wrapper allows passing constructors as callbacks, where `new` is required. --- diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index 8d06cec..c164b6a 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -365,6 +365,18 @@ IPython.utils = (function (IPython) { test.remove(); return Math.floor(points*pixel_per_point); }; + + var always_new = function (constructor) { + // wrapper around contructor to avoid requiring `var a = new constructor()` + // useful for passing constructors as callbacks, + // not for programmer laziness. + // from http://programmers.stackexchange.com/questions/118798 + return function () { + var obj = Object.create(constructor.prototype); + constructor.apply(obj, arguments); + return obj; + }; + }; var url_path_join = function () { @@ -416,6 +428,7 @@ IPython.utils = (function (IPython) { points_to_pixels : points_to_pixels, url_path_join : url_path_join, splitext : splitext, + always_new : always_new, browser : browser };