Plato on Github
Report Home
triggermethod.js
Maintainability
56.89
Estimated # Bugs
0.18
Difficulty
11.79
SLOC/LSLOC
19 / 16
Function weight
By Complexity
By SLOC
// Trigger an event and a corresponding method name. Examples: // // `this.triggerMethod("foo")` will trigger the "foo" event and // call the "onFoo" method. // // `this.triggerMethod("foo:bar") will trigger the "foo:bar" event and // call the "onFooBar" method. Marionette.triggerMethod = function(){ var args = Array.prototype.slice.apply(arguments); var eventName = args[0]; var segments = eventName.split(":"); var segment, capLetter, methodName = "on"; for (var i = 0; i < segments.length; i++){ segment = segments[i]; capLetter = segment.charAt(0).toUpperCase(); methodName += capLetter + segment.slice(1); } this.trigger.apply(this, args); if (_.isFunction(this[methodName])){ args.shift(); return this[methodName].apply(this, args); } };