From 50f19777781cca115e5aef51b2809a54af93da23 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 31 Jul 2013 12:25:08 +0200 Subject: [PATCH] =?utf8?q?kivi.js:=20Funktion=20zum=20Auffinden=20von=20Fu?= =?utf8?q?nktionen=20=C3=BCber=20ihren=20Namen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Funktioniert sowohl mit globalen Funktionen als auch mit solchen in Namensräumen (Objekten): var func = kivi.get_function_by_name("kivi.t8"); --- js/kivi.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/kivi.js b/js/kivi.js index ea892f521..5901c89a1 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -37,6 +37,17 @@ namespace("kivi", function(ns) { kivi.PartPicker($(elt)); }); }; + + // Return a function object by its name (a string). Works both with + // global functions (e.g. "check_right_date_format") and those in + // namespaces (e.g. "kivi.t8"). + // Returns null if the object is not found. + ns.get_function_by_name = function(name) { + var parts = name.match("(.+)\\.([^\\.]+)$"); + if (!parts) + return window[name]; + return namespace(parts[1])[ parts[2] ]; + }; }); kivi = namespace('kivi'); -- 2.20.1