add utils.always_new

wrapper allows passing constructors as callbacks, where `new` is required.
pull/37/head
MinRK 13 years ago
parent 111fccc8ab
commit 9206d1e87f

@ -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
};

Loading…
Cancel
Save