两个javascript小测试例子 类和json函数
2015-08-27 16:26
447 查看
两个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>
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>
相关文章推荐
- js Map和Set
- js循环
- js循环
- js对象
- C# 窗体中 webbrowser 中 javascript 调用窗体方法 实例
- js获取下拉框属性值的写法
- C# 窗体 webbrowser 窗体调用javascript方法 实例
- JS基础知识梳理---Array对象
- $.each遍历json对象
- js闭包
- js实现简易计算器功能
- String to Date jstl标签的fmt:formatDate格式化日期
- seaJs使用记录
- JS学习之闭包的理解
- json格式字符串转集合
- 闭包-JS
- js 保持在不同区域鼠标动作不被中断
- 用js识别字符串中的英文字母字符和非字符(汉字)
- javascript常见的20个问题与解决方法
- JS执行流程