The right example:
var person=function (name,age) {this . Name= "; This. Age= "; This. Say=function (msg) { alert (msg); } This.init=function (name,age) {this . Name=name; This. age=age; } This.init (name,age); var fun=function () { alert (' fun '); } This.funshow=function () {fun (); }
<pre name= "code" class= "HTML" > var mutilfun=function () { <pre name= "code" class= "HTML" > Say ();
<span style= "font-family:arial, Helvetica, Sans-serif;" > This . Say ();</span>
}
This.mutilfunshow=function () { <pre name= "code" class= "HTML" > mutilfun ();
}
Fun ();} Call: Var jon=new person (' Jon ', 26); Jon.say (' Go away '); Alert (jon.name+jon.age), above all to Var shaw=new person (' Shaw ', 26);
Shaw.fun ();
<pre name= "code" class= "HTML" > shaw.funshow ();//This is right. Other Shaw is wrong.
Shaw.mutilfunshow ();//This inside is capable of running to mutilfun this culvert, but <span style= "font-family:arial, Helvetica, Sans-serif;" >mutilfun this number of errors, because Mutilfun in This.say () is not the person in this class This.say (). This here refers to the </span><span style= "font-family:arial, Helvetica, Sans-serif;" >mutilfun, not person. </span>
Shaw, this object is wrong.
Why Shaw.fun () will be wrong, and the reported error isShaw.fun () is not a function. Because fun is not a property of Shaw, if the attribute is not var;
But Shaw.funshow () is right.
a person is a class and a method, and it is more appropriate to say the method with attributes. Person inside is also step by step execution pull down, first run this.init (name,age), in Run Fun ().
JavaScript creates class objects