Wednesday, 22 July 2015
Adding public and private method/property
Here is how you returns a Person object to the caller:
function Person(name)
{
// increase the head count (static property)
this.constructor.headCount++;
// private variable
var _dob;
var _name = name;
//public functions
this.helo = function () { return 'helo work..' };
this.toString = function () { return _name };
// public property
this.money = 1000;
}
// public functions
Person.prototype.sayMyName = function () { return this.toString() };
Person.prototype.myBalance = function () { return this.money; };
// static property
Person.headCount = 0;
var p1 = new Person('mike');
var p2 = new Person('john');
var count = Person.headCount; // the output is '2' because you called 'new' twice
For detail explanation, please refers to the following artcile:
http://phrogz.net/JS/classes/OOPinJS.html
Subscribe to:
Post Comments (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...
-
Below is the sample HTML which will hide the URL at the page header when printing with Javascript. <html moznomarginboxes > ...
-
You can draw a simple pie chart & doughnut chart with SVG + CSS. This is quite simple and straight forward. But the limitation is that i...
No comments:
Post a Comment