JS class of the wording:
1, writing one: function inside contains this.function () such as code:
varOrigin_class =function (name) {varLover ="'; This. Getlover =function (hername) {return This. Lover =Hername;} This. Show =function (hername) {return This. Getlover (Hername) +' Love'+name;}}vartalk =NewOrigin_class ('Modle'); Talk.getlover ('Zhongyaji'); Talk.show ('Zhongyaji');
2, using the object structure method (can not be instantiated, but also a class bar, because it contains many methods):
var modle = {sayhello:function () { console.log ('hello');}}; Modle.sayhello ();
3, the prototype method (actually just for inheritance, very similar to Java inheritance, etc.):
var hello = function () {
this. You = function () {
Console.log ('you');
}
}
Here is the inheritance, like Java, before the instantiation of inheritance before, there is a way to
This ah, because of inheritance, can no longer this.me, all inherited, how may or oneself?
{
Me:function ()
{
Console.log (' Me ');
}
}hello.prototype.me=function ()
{
Console.log ('me');
}varnew hello (); show.me ();
4, the protection in the object is not exposed
varApp = { //similar to constructors, execution of Init takes effect only, otherwise it is simply defined.init:function () {}, Showlove:function () {Console.log ('Show'); }, Hello:function () {Console.log ('fuck!') }}//if one of the methods is private and does not want to be exposed, then sovarOutput = { //so you can not expose some of the methods in the apphello:app.showLove ();} App.init ();
5, there is another way
$ (' #selector '). Load (' index.php #container ');
Meaning a bit like the Get method of Ajax, get index.php #container Middle content
My master's JS Knowledge JS class, single-write template, and the method of private protection