|
Answer» Please SEE the below example for how to create the namespace in JavaScript.
//Create the namespace. var nameSpace = nameSpace || {}; nameSpace.myEmpConsepts = function () { var empId = "00201"; //This is a PRIVATE variable. this.empName = "ANIL Singh"; //This is a public variable. //This is public function this.getEmp = function () { RETURN "Anil Singh" } //This is private function var getEmp = function () { return "Anil Singh" } return { getEmp: getEmp,// work as public getEmp: getEmp // work as public } }(); Please see the below example for how to create the namespace in JavaScript. //Create the namespace. var nameSpace = nameSpace || {}; nameSpace.myEmpConsepts = function () { var empId = "00201"; //This is a private variable. this.empName = "Anil Singh"; //This is a public variable. //This is public function this.getEmp = function () { return "Anil Singh" } //This is private function var getEmp = function () { return "Anil Singh" } return { getEmp: getEmp,// work as public getEmp: getEmp // work as public } }();
|