Spencer Ruport
Spencer Ruport

Reputation: 35117

How does knockout create functions from property bindings?

When I set a knockout binding property as some javascript statement how is knockout able to wrap it in a function?

Statement gets wrapped in a function

If I create an object like so:

var myObject = {
    'text': Data.Info.Title()
};

The text property is going to be set with the value of title. How could I get this to be a function instead?

Upvotes: 0

Views: 53

Answers (1)

GôTô
GôTô

Reputation: 8053

In your binding, it works because knockout parses the binding, which is not the case in your second example.

The text property is going to be set with the value of title. How could I get this to be a function instead?

Simply remove the parenthesis:

var myObject = {
    'text': Data.Info.Title
};

Works also on the binding:

<span data-bind="text: Data.Info.Titleasdasdasd"></span>

Upvotes: 1

Related Questions