码迷,mamicode.com
首页 > 编程语言 > 详细

两个javascript小测试例子 类和json函数

时间:2015-08-27 18:01:35      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

两个javascript小测试例子 类和json函数

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>

两个javascript小测试例子 类和json函数

标签:

原文地址:http://www.cnblogs.com/xiaofeng-1/p/4763715.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!