JS関数の宣言とアクセス原理
1576 ワード
<script type="text/javascript">
//
var testClass = function(){
// ( , )
this.age ="25";
// ( )
name="jack";
// ( )
var address = "beijing";
// ( )
add = function(a,b){
// :
multiply(a,b);
return a+b;
}
// ( )
this.minus = function(a,b){
// : 、
return a-b;
}
// ( )
var multiply = function(a,b){
// :
return a*b;
}
}
// ( )
testClass.talk= function(){
// :
this.what = function(){
alert("What can we talk about?");
about();
}
var about = function(){
alert("about name:"+name);
alert("about add(1,1):"+add(1,1));
}
}
// ( )
testClass.prototype.walk = function(){
// :
this.where = function(){
alert("Where can we go?");
go();
}
var go = function(){
alert("go name:"+name);
alert("go add(1,1):"+add(1,1));
}
}
</script>
:
<script type="text/javascript">
// cbs
var cbs= new testClass();
// age
alert("age:"+cbs.age);
// talk
var talk = new testClass.talk();
//
talk.what();
// walk
var walk = new cbs.walk();
//
walk.where();
</script>