<!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(","))
})()

最新文章

  1. SQL数据库 开启时出现 数据库连接错误2,error:40的问题。如何解决
  2. Ajax Step By Step1
  3. 阅读《LEARNING HARD C#学习笔记》知识点总结与摘要二
  4. jsp EL 表达式
  5. fedora 添加其他操作系统到 GRUB 2 菜单
  6. [C程序设计语言]第二部分
  7. JS constructor
  8. oracle 在表中有数据的情况下修改表字段类型或缩小长度
  9. Worker、Task、Executor三者之间的关系
  10. MapReduce流程、如何统计任务数目以及Partitioner
  11. 泛泰A870L/K/S第三版官方4.4.2原来的系统卡刷机包 (愿自己主动ROOT)
  12. Java 服务器端手机验证码sdk
  13. Java 导出Excel的各种尝试
  14. bzoj3811 玛里苟斯
  15. 学习React Native必看的几个开源项目
  16. IDEA 代码风格设置
  17. criteo marketing api 相关
  18. 在linxu机器ansible上运行启动django项目命令
  19. [原]windows sdk版本不对
  20. 解决ie浏览器下载apk或ipa变为zip

热门文章

  1. 帆软FineBI试用
  2. Linux下FTPserver的实现(仿vsftpd)
  3. UI_UISegmentedControl 控件
  4. 用motion实现家庭视频监控
  5. PipeCAD之管道标准库PipeStd(2)
  6. 深入Vue的响应式原理
  7. android的HTTP框架之Volley
  8. Firefox 浏览器添加Linux jre插件
  9. 在Windows上如何安装和彻底卸载Adobe Flash Player教程
  10. 使用js实现简单放大镜的效果