Johan
Johan

Reputation: 35194

Durandal computed prototype methods

Is it possible to define a computed property on my view model prototype? As far as I can tell, there is no way to access a proper this value at the time of declaration.

I can put it inside the constructor, but then it'll be redefined for each instance as you know. So in the end this is just a question of performance.

My AMD module for my view model:

function viewModel(){
    // this.someComputed works
}

viewModel.prototype.someComputed = ko.pureComputed(function(){

}/*, no context yet..? */);

viewModel.prototype.activate = function(){
    // 'this' is an instance of the view model (I presume)
    // should I attach it here?
};

return viewModel;

Upvotes: 1

Views: 112

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074355

Is it possible to define a computed property on my view model prototype? As far as I can tell, there is no way to access a proper this value at the time of declaration.

Correct. So the answer is no, you can't use computeds on prototype methods.

Upvotes: 2

Related Questions