Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use parentheses in knockout

I am a beginner in Knockout and I must say I often get confused regarding when to use (). Is there any general tip/trick regarding when would you use () against when you would not because at the moment I am just doing trial and error. If the binding throws error or doesn't update values I remove () else I put.

like image 825
Tim Tom Avatar asked Jun 12 '12 11:06

Tim Tom


People also ask

How do you apply knockout?

Hold can at arm's length and direct spray toward the area to be treated. Use a sweeping motion to apply product and back away from treated area while holding the can 36 inches away from the surface being treated. Areas of 80-100 sq ft can be treated in approximately 10 seconds with Knockout E. S.

What is Knockout used for?

Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model.

What is knockout in web development?

Knockout. js is a minimalist JavaScript framework for web application development. It is a JavaScript library that allows binding HTML elements against any data model. It is primarily used for creating rich and responsive display as well as editor user interfaces with a clean, underlying data model.


1 Answers

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.

like image 107
Kyeotic Avatar answered Oct 05 '22 17:10

Kyeotic