varClass =function(){ varKlass =function(){ This. init.apply ( This, arguments); }; //InitKlass.prototype.init =function(){}; returnKlass; }; varperson =NewClass (); Person.prototype.init=function(){ This. Name = "Jackey"; }; Person.prototype.find=function() {Console.log ( This. Name); }; varperson =NewPerson (); Person.find ();
(1)
var New Class ();
To create this effect, we first write a class function, which is instantiated to return a function:
var function () { varfunction() {}; return Klass; };
(2) Add a program entry to the return function
var function () { varfunction() { this. init.apply (This, arguments); }; // Init function (){}; return Klass; };
This means that the this pointer variable for the init of the returned function prototype will be referenced to the Klass
(3) Writing classes, using prototypes to expand their function
var New Class (); function () { this. Name = "Jackey"; }; function () { Console.log (this. Name); }; var New Person (); Person.find ();
(1) Basic JavaScript MVC pattern