diff --git a/src/index.js b/src/index.js index 54653a5..07f7c53 100644 --- a/src/index.js +++ b/src/index.js @@ -35,11 +35,29 @@ } /** - * @return {Energy} + * @return {Energy} emitter instance */ function energy(o) { return o instanceof Energy ? o[init]() : new Energy(o); - } + } + + /** + * @this {Function} wrapper that constructs the source instance + * @param {Object|Function} target to convert into emitter + * @return {Object|Function} target converted into emitter + */ + energy['into'] = function(target) { + return defaults(target, this.call()); + }; + + /** + * @this {Energy|Object|Function} source emitter + * @param {Object|Function} target to convert into emitter + * @return {Object|Function} target converted into emitter + */ + emitter['into'] = function(target) { + return defaults(target, this); + }; /** * @param {{length:number}} fns diff --git a/test/index.js b/test/index.js index 36107df..639cfbb 100644 --- a/test/index.js +++ b/test/index.js @@ -11,7 +11,19 @@ function yes() { return true; } aok('instance', emitter instanceof energy); - aok('listeners', typeof emitter.listeners(key).length == 'number'); + aok('listeners', typeof emitter.listeners(key).length == 'number'); + + aok('into', function() { + function wannabe() { + wannabe.emit('called'); + } + + var bool = wannabe === energy.into(wannabe) && typeof wannabe.emit == 'function'; + bool && wannabe.once('called', function() { + bool = this === wannabe; + }) && wannabe(); + return bool; + }); (function(id) { var bool = true, gone = indexOf ? function(what) {