Javascript calling public function in a private function in a class

Exactly like the title, here is a demo of Javascript calling public function in a private function in a class.
[code language=”javascript”]
var hello = function()
{
this.hey = function(){ console.log("hey"); }

var _this = this; // store this(the hello class) to _this
var init = function init()
{
_this.hey(); // If use this here, it will throw error, because this here refers to the window context
}

init();
}
var h = new hello();
[/code]

Search within Codexpedia

Custom Search

Search the entire web

Custom Search