1
votes

I have a knockout observable and I'm trying to run a function when it is not undefined, but I keep getting the error below. Here is my view model:

View Model:

self.prevLayer = ko.observable();

if (typeof self.prevLayer() !== "undefined") {
   DoStuff();
}

Here is my error:

Message: undefined is not a function

1
Can you post more of your view model? I think we need more context. - Matt Burland
Which function - the self.prevLayer, the ko.observable or the DoStuff? Do you overwrite the prevLayer somewhere else in your code? - mfeineis

1 Answers

2
votes

Are you checking to see if it is undefined outside of your view model?

If so, you will need to move it inside the view model, the variable only exists inside your view model.