When should I use parentheses in knockout

I feel like the existing answers skip over a very important point of confusion: data-bind attributes.

It is true that you use the parens when you are in Javascript, and getting or setting observables. But when you are writing data-bind="text: property", you leave out the parens even when working with observables.

Edit

As noted in the comment below, bindings that are expressions, or access properties of observbles, require parens

visible: personName().length > 0
visible: person().Name().length > 0
visible: person().isVisible

Note that the last one person and isVisisble are both observables, but the last property doesn’t use parens! The reason for this is that we would be passing a value to the binding instead of an observable, and it wouldn’t update.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)