Instead of having to use ko.applyBindings(new SomeClass()); to activate knocokout on a class, could I just use ko.applyBindings(this); within the constructor of SomeClass? I find it bad OOP in my opinion to have to apply it outside of the class. Wouldn’t it be better to define in the class what it is supposed to do?
Instead of having to use ko.applyBindings(new SomeClass()); to activate knocokout on a class, could
Share
If
SomeClassis the constructor for your overall view model and you are not going to create multiple instances ofSomeClass, then you could callko.applyBindingsfrom within the constructor.Calling
ko.applyBindingsmultiple times on the same elements has some bad side-effects (multiple bindings + multiple event handlers attached), so you would want to be careful that you only call is once or call it passing different DOM elements to be the root as the second argument.