js34
2024-08-23 14:56:41
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type=text/javascript charset=utf-8>
(function(){
//2中函数声明的区别
add(1,1);
function add(x,y){
alert(x+y)
}
add(1,2); //add2(12,3)//不能调用
var add2 = function(x,y){
alert(x+y)
}
add2(12,3) //传值还是传址,string是基础类型,
var i = 100;
var s = "one";
function add3(i,s){
i++;
s+="--"
}
alert(i);//100 or 101
alert(s);//"one"
})() var a = 3;
var b = [a];
alert(b instanceof Array);
alert(b[0]); var a = "[1,2,3,4,5]";
var array = eval(a);//string变数组
for (var i = 0; i < array.length; i++) {
alert(array[i])
} //解析成函数,并且调用
var str = "var show = function(){alert(100)}()";
eval(str); new person().showName();
var cat = {};
Object.getPrototypeOf(cat).name = "MAOMI";
cat.__proto__.master = "USPCAT.COM"; var a = {};//空类
a.__proto__ = person.prototype; var b = {};
b.__proto__ = new person();
b.__proto__.constructor = b; var JSON = {}; JSON.prototype = {
toJSONString :function(){
var outPut = [];
for(key in this){
outPut.push(key+" -- "+this[key])
}
return outPut;
}
} function mixin(receivingClass,givingClass){
for(methodName in givingClass.prototype){
//本类中没有这个函数的情况下我在聚合,否则跳过
receivingClass.prototype[methodName] = givingClass.prototype[methodName]
}
} var o = function(){
this.name = "YUN";
this.age = 17
} mixin(o,JSON);
alert(JSON.prototype.toJSONString);
alert(o.prototype.toJSONString);
var a = new o();
alert(a.toJSONString()); JSON.prototype['toJSONString'] = function(){
var outPut = [];
for(key in this){
outPut.push(key+" ------ "+this[key])
}
return outPut;
} mixin(o,JSON);
alert(JSON.prototype.toJSONString);
alert(o.prototype.toJSONString);
alert(a.toJSONString()); </script>
</head>
<body>
</body>
</html>
/**
* 掺元类
* 有的适合只需要继承一个类(几个)中的一些函数
*
*/
(function(){
//我们准备将要被聚合的函数
var JSON = {
toJSONString :function(){
var outPut = [];
for(key in this){
outPut.push(key+" --> "+this[key])
}
return outPut;
}
};
/**
* 聚合函数
*/
function mixin(receivingClass,givingClass){
for(methodName in givingClass){
if(!receivingClass.__proto__[methodName]){ //通过中括号访问json
receivingClass.__proto__[methodName] = givingClass[methodName]
}
}
}
var o = {name:"YUN",age:27}
mixin(o,JSON);
document.write(o.toJSONString().join(",")) //-------------------------------------------------------------------
JSON.prototype = {
toJSONString :function(){
var outPut = [];
for(key in this){
outPut.push(key+" --> "+this[key])
}
return outPut;
}
}
//制作聚合函数
function mixin(receivingClass,givingClass){
for(methodName in givingClass.prototype){
//本类中没有这个函数的情况下我在聚合,否则跳过
if(!receivingClass.prototype[methodName]){
//传递的是地址
receivingClass.prototype[methodName] = givingClass.prototype[methodName]
}
}
} //----------------------------------------------------------
//var o = {name:"YUN",age:27}
var o = function(){
this.name = "YUN";
this.age = 17
}
mixin(o,JSON);
var a = new o();
document.write(a.toJSONString().join(","))
})()
最新文章
- SQL数据库 开启时出现 数据库连接错误2,error:40的问题。如何解决
- Ajax Step By Step1
- 阅读《LEARNING HARD C#学习笔记》知识点总结与摘要二
- jsp EL 表达式
- fedora 添加其他操作系统到 GRUB 2 菜单
- [C程序设计语言]第二部分
- JS constructor
- oracle 在表中有数据的情况下修改表字段类型或缩小长度
- Worker、Task、Executor三者之间的关系
- MapReduce流程、如何统计任务数目以及Partitioner
- 泛泰A870L/K/S第三版官方4.4.2原来的系统卡刷机包 (愿自己主动ROOT)
- Java 服务器端手机验证码sdk
- Java 导出Excel的各种尝试
- bzoj3811 玛里苟斯
- 学习React Native必看的几个开源项目
- IDEA 代码风格设置
- criteo marketing api 相关
- 在linxu机器ansible上运行启动django项目命令
- [原]windows sdk版本不对
- 解决ie浏览器下载apk或ipa变为zip