From 1b97996ef8907726f12d3752faa4434df156d9ac Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 7 Sep 2017 12:26:05 +0200 Subject: [PATCH] implement util.once --- www/common/common-util.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/www/common/common-util.js b/www/common/common-util.js index 8cbde420c..e42a0249c 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -170,5 +170,15 @@ define([], function () { return parts[0]; }; + /* for wrapping async functions such that they can only be called once */ + Util.once = function (f) { + var called; + return function () { + if (called) { return; } + called = true; + f.apply(this, Array.prototype.slice.call(arguments)); + }; + }; + return Util; });