Is this related to knockout.js specifically, or are you just trying to sort a plain ECMAScript issue? Any...
It's usually best not to use a function expression where a declaration will do, and constructors should start with a captial letter to let others know that they are constructors.
function App() {
var self = this;
It is unclear why you want to do that. Keeping a reference to this is not common in a constructor.
this.index = 0;
myfunction = function(){
Here's where you get into trouble. When the consructor is called for the first time, the above will create a global variable named myfunction. That probaby isn't what you want to do. A function declaration will stay local, unequivocally. But the function should probaby be on App.prototype anyway.
function myFunction() {
.
//how can i modify index here
self.index = 1;
};
that function will modify the index property, but only if it's called. So what you might do is:
function App(){
this.index = 0; // Each instance will have an index property
}
// All instances will share a myfunction method
App.prototype.myfunction = function() {
this.index = 1;
console.log(this.index);
}
var app = new App();
app.myfunction(); // 1