Most of the time, we don't know what is "this"? Is it a "window", jQuery object, or what is it. It is difficult to debug and make the code to work.
One of the easiest solution that I found is to capture the context into "self" and then all public functions to be declared with the object function. For example, sayHelo() will always referring to the same context as you call the setMyName().
function myClass() {
var self = this;
var name;
this.setMyName = function (s) { name = s; };
this.getMyName = function() { return name; };
this.sayHelo = function() { return self.getMyName(); };
}
var c = new myClass();
c.setMyName('Mickey');
console.log(c.sayHelo());
Wednesday, 12 July 2017
Subscribe to:
Posts (Atom)
We are moving
We are moving this blog to our new blog site: https://ciysys.com/blog/nodejs.htm
-
Overview Usually, we start developing a new system with designing database and then writing codes. If you are not a fan of ORM, you will h...
-
I'm working on an attendance audit screen which allows the user to single click to confirm the selection and double click to create a re...
-
You cannot achieve the fixed row and column with HTML + CSS. You need the Javascript as well. Below is the HTML, CSS and Javasript th...