2021-03-16 02:41:05 +00:00
|
|
|
import { helper } from '@ember/component/helper';
|
|
|
|
import { assert } from '@ember/debug';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bind
|
|
|
|
*
|
|
|
|
* Usage: {{bind this.function}}
|
|
|
|
*
|
|
|
|
* Returns a version of a function bound to the template target (e.g., component or controller)
|
|
|
|
*/
|
|
|
|
export function bind([func, target]) {
|
2021-12-28 16:08:12 +00:00
|
|
|
assert(
|
|
|
|
'A function is required as the first argument',
|
|
|
|
typeof func === 'function'
|
|
|
|
);
|
2021-03-16 02:41:05 +00:00
|
|
|
assert('A context is required as the second argument', target);
|
|
|
|
return func.bind(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default helper(bind);
|