Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #298 from snichme/master

Make functions defined in events: {} to be called in correct context
  • Loading branch information...
commit 5e0ff36ee36588602f7f9c68ab583a9e5f817867 2 parents b809c99 + 16c557b
@maccman maccman authored
Showing with 13 additions and 2 deletions.
  1. +8 −1 lib/spine.js
  2. +5 −1 src/spine.coffee
View
9 lib/spine.js
@@ -724,7 +724,14 @@
_results = [];
for (key in events) {
method = events[key];
- if (typeof method !== 'function') {
+ if (typeof method === 'function') {
+ method = (function(method) {
+ return function() {
+ method.apply(_this, arguments);
+ return true;
+ };
+ })(method);
+ } else {
method = (function(method) {
return function() {
_this[method].apply(_this, arguments);
View
6 src/spine.coffee
@@ -425,9 +425,13 @@ class Controller extends Module
delegateEvents: (events) ->
for key, method of events
- unless typeof(method) is 'function'
+ if typeof(method) is 'function'
# Always return true from event handlers
method = do (method) => =>
+ method.apply(this, arguments)
+ true
+ else
+ method = do (method) => =>
@[method].apply(this, arguments)
true
Please sign in to comment.
Something went wrong with that request. Please try again.