User Tools

Site Tools


misc:oojavascript

This is an old revision of the document!


Object Oriented Javascript

Example Class

function OOClass()
{	this.local_public = "public";
	var local_private = "private";
 
	this.publicTest = function()
	{	console.log("privprintfunc: "+this.local_public);
	}
	var privTest = function()
	{	console.log("privprintfunc: "+local_private);
	}
}

Public Fields

this.local_public = "public";
  • Public fields must be addressed with the this. prefix when used within the class definition and with the <OBJ>. prefix when used outside of the class definition.

Private Fields

var local_private = "private";
  • Private fields must be addressed without any prefix and cannot be directly address outside of the class definition.

Public method

var publicTest = this.publicTest;
this.publicTest = function()
{	console.log("privprintfunc: "+this.local_public);
}

Private Method

var privTest = function()
{	console.log("privprintfunc: "+local_private);
}
misc/oojavascript.1475689268.txt.gz · Last modified: 2016/10/05 12:41 by tschulz