forked from jcoglan/jsclass
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changing Module so that it provides included() and extended() hooks, …
…so that modules can define class methods as well as instance methods. Made exclusion of methods include(), included(), extend() and extended() consistent between instance and class methods, and changed Forwardable to reflect these changes.
- Loading branch information
Showing
2 changed files
with
22 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
JS.Forwardable = { | ||
extended: function(klass) { | ||
klass.extend({ | ||
|
||
defineDelegator: function(subject, method, alias) { | ||
alias = alias || method; | ||
this.instanceMethod(alias, function() { | ||
var object = this[subject], property = object[method]; | ||
return typeof property == 'function' | ||
? property.apply(object, arguments) | ||
: property; | ||
}); | ||
}, | ||
|
||
defineDelegators: function() { | ||
var methods = Array.from(arguments), subject = methods.shift(); | ||
for (var i = 0, n = methods.length; i < n; i++) | ||
this.defineDelegator(subject, methods[i]); | ||
} | ||
JS.Forwardable = JS.Module({ | ||
defineDelegator: function(subject, method, alias) { | ||
alias = alias || method; | ||
this.instanceMethod(alias, function() { | ||
var object = this[subject], property = object[method]; | ||
return typeof property == 'function' | ||
? property.apply(object, arguments) | ||
: property; | ||
}); | ||
}, | ||
|
||
defineDelegators: function() { | ||
var methods = Array.from(arguments), subject = methods.shift(); | ||
for (var i = 0, n = methods.length; i < n; i++) | ||
this.defineDelegator(subject, methods[i]); | ||
} | ||
}; | ||
}); |