From 7d847f25dc20d842e859df24f51f2823fe849bce Mon Sep 17 00:00:00 2001 From: Fabien Franzen Date: Mon, 11 Aug 2014 19:07:48 +0200 Subject: [PATCH] Fix scopeMethods closure issue --- lib/relation-definition.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/relation-definition.js b/lib/relation-definition.js index eeafd328..0074f318 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -64,12 +64,15 @@ function extendScopeMethods(definition, scopeMethods, ext) { if (typeof ext === 'function') { customMethods = ext.call(definition, scopeMethods, relationClass); } else if (typeof ext === 'object') { + function createFunc(definition, relationMethod) { + return function() { + var relation = new relationClass(definition, this); + return relationMethod.apply(relation, arguments); + }; + }; for (var key in ext) { var relationMethod = ext[key]; - var method = scopeMethods[key] = function () { - var relation = new relationClass(definition, this); - return relationMethod.apply(relation, arguments); - }; + var method = scopeMethods[key] = createFunc(definition, relationMethod); if (relationMethod.shared) { sharedMethod(definition, key, method, relationMethod); }