Javascript public private methods.

function class11() { var a=1; // private var var b=2; this.c=4; // public var var func1 = function () // private function cannot access public varibale { console.log(a+" "+b+" "+this.c); return "private func()"; }; this.func2 = function() // priviledge function can access both private public { //func1(); console.log(a+" "+b+" "+this.c); return "public func"; }; class11.prototype.func3= function(){ // public prototypic function. // func1(); // can access private //this.func2();// can access previledge console.log(a+" "+b+" "+this.c); return("public..meth"); }; } var obj = new class11(); //console.log(obj.a); //console.log(obj.c); console.log(obj.func1); console.log(obj.func2()); console.log(obj.func3()); //In javascript : /* 1. var = private this= public variable . 2. private methods not availble to object / dot notation : result undefined. // 3. previledge (this.meth = function ) & public is available to object. 4. previlege methods can access all - private / public var/meth. 5. public method can access private method ( as per books it should not) , priviledge, public methods. // also all var are accesible. 6. private method cannot access public variable. 7. privilege & public can access private and public varibales. */

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.