From 2e565dcfce3d4c7e87df07a982260a5769eb8428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 11 Jun 2013 19:07:25 -0700 Subject: [PATCH] Fix Function#name on browsers that don't support it. Closes #236. --- src/core/Base.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/Base.js b/src/core/Base.js index 83cab6a6..d7e106f7 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -10,6 +10,15 @@ * All rights reserved. */ +// First check if Function#name works, and if not, fix it by injecting a getter +if (!(function f() {}).name) { + Base.define(Function.prototype, 'name', { + get: function() { + return this.toString().match(/^function\s?(\w*)\(/)[1]; + } + }); +} + /** * @name Base * @class