I've written a few custom bindings using KnockoutJS. I'm still unsure when to use ko.utils.unwrapObservable(item)
Looking at the code, that call basically checks to see if item
is an observable. If it is, return the value(), if it's not, just return the value. Looking at the section on Knockout about creating custom bindings, they have the following syntax:
var value = valueAccessor(), allBindings = allBindingsAccessor();
var valueUnwrapped = ko.utils.unwrapObservable(value);
In this case, they invoke the observable via ()
but then also call ko.utils.unwrapObservable
. I'm just trying to get a handle on when to use one vs. the other or if I should just always follow the above pattern and use both.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…