posts - 495,comments - 227,trackbacks - 0

one.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>function this 的使用</title>
</head>

<body>
<script type="text/javascript" language="javascript">
cls=function(data){
 this.showA=function (a){
  alert(a);
 };
 //showA('showA');
 this.showA("ccc")
 function showB(b){
  alert(b);
 };
 showB("ddd")
 function showData(data){
  alert(data);
 };

}
var c=new cls("simone");
c.showA("asmone");
c.showB("tt");
cls.showB("b");
cls.showData("wang");
alert(cls("simone"));
</script>
</body>
</html>



two.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>function : 的使用</title>
</head>

<body>
<script type="text/javascript" language="javascript">
var FN=function(s){
 alert('fn');
 alert(s);
 return{
  nopar:function(){alert('nopar')},
  onepar:function(p){alert('onepar');alert(p)},
  shows:function(){alert(s)},
  shows2:function(s){alert(s)}
 }
}
fn=new FN('onefn');
fn.nopar();
fn.onepar('ts');
fn.shows();
fn.shows2('tbb');

alert('******************');

var FN2={
 one:function(){alert('one')},
 two:function(p){alert(p),alert(this)},
 three:function(){
  this.one();
  alert('three');
  function in_three(){
   alert('in_three');
  };
  this.this_three=function(){
   alert('this_three');
  };
 }
};
FN2.one();
FN2.two('fn2 two');
FN2.three();
var three2=FN2.three;
alert('########');
var th=new three2();//去掉this.one()这一语句后,可以new成功
th.this_three();
</script>
</body>
</html>

posted on 2008-02-16 11:45 SIMONE 阅读(1395) 评论(1)  编辑  收藏 所属分类: JavaScript

FeedBack:
# re: 两个javascript小测试例子 类和json函数[未登录]
2010-11-23 15:53 |
阿斯顿  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: