--- title: Use {{fn}} for Partial Application Only impact: LOW-MEDIUM impactDescription: Clearer code, avoid unnecessary wrapping tags: helpers, templates, fn, partial-application --- ## Use {{fn}} for Partial Application Only The `{{fn}}` helper is used for partial application (binding arguments), similar to JavaScript's `.bind()`. Only use it when you need to pre-bind arguments to a function. Don't use it to simply pass a function reference. **Incorrect (unnecessary use of {{fn}}):** ```glimmer-js // app/components/search.gjs import Component from '@glimmer/component'; import { action } from '@ember/object'; class Search extends Component { @action handleSearch(event) { console.log('Searching:', event.target.value); } } ``` **Correct (direct function reference):** ```glimmer-js // app/components/search.gjs import Component from '@glimmer/component'; import { action } from '@ember/object'; class Search extends Component { @action handleSearch(event) { console.log('Searching:', event.target.value); } } ``` **When to Use {{fn}} - Partial Application:** Use `{{fn}}` when you need to pre-bind arguments to a function, similar to JavaScript's `.bind()`: ```glimmer-js // app/components/user-list.gjs import Component from '@glimmer/component'; import { action } from '@ember/object'; class UserList extends Component { @action deleteUser(userId, event) { console.log('Deleting user:', userId); this.args.onDelete(userId); } } ``` **Multiple Arguments:** ```glimmer-js // app/components/data-grid.gjs import Component from '@glimmer/component'; import { action } from '@ember/object'; class DataGrid extends Component { @action updateCell(rowId, columnKey, event) { const newValue = event.target.value; this.args.onUpdate(rowId, columnKey, newValue); } } ``` **Think of {{fn}} like .bind():** ```javascript // JavaScript comparison const boundFn = this.deleteUser.bind(this, userId); // .bind() pre-binds args // Template equivalent: {{fn this.deleteUser userId}} // Direct reference const directFn = this.handleSearch; // No pre-binding // Template equivalent: {{this.handleSearch}} ``` **Common Patterns:** ```javascript // ❌ Wrong - no partial application // ✅ Correct - direct reference // ✅ Correct - partial application with argument // ❌ Wrong - no partial application // ✅ Correct - direct reference // ✅ Correct - partial application with field name ``` Only use `{{fn}}` when you're binding arguments. For simple function references, pass them directly. Reference: [Ember Templates - fn Helper](https://guides.emberjs.com/release/components/template-lifecycle-dom-and-modifiers/#toc_passing-arguments-to-functions)