js34
<!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(","))
})()
js34的更多相关文章
- 前端试题本(Javascript篇)
JS1. 下面这个JS程序的输出是什么:JS2.下面的JS程序输出是什么:JS3.页面有一个按钮button id为 button1,通过原生的js如何禁用?JS4.页面有一个按钮button id为 ...
- RFID-RC522、FM1702SL、M1卡初探
catalogue . 引言 . RC522芯片(读卡器)简介 . FM1702SL芯片(读卡器)简介 . RFID M1卡简介 . 读取ID/序列号(arduino uno.MFRC522芯片 Ba ...
- CentOS6.5安装MySql5.5
最近在CentOS上安装MySql,本来以为yum安装会很简单,但是却花了自己不少时间,所以决定和大家分享下. 首先,安装MySql源! 下载地址:http://dev.mysql.com/downl ...
- Bad Hair Day【单调栈】
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAzMAAANgCAIAAACX06G4AAAgAElEQVR4Aey9e5RlW13fuw40HORxfI ...
随机推荐
- 杯子 (glass)
题目 试题1:杯子 (glass) 源代码:glass.cpp 输入文件:glass.in 输出文件:glass.out 时间限制:1s 空间限制:256MB 题目描述 小明买了N个容积可以 ...
- Mongo集群之主从复制
上线的系统.数据存储是重要部位.若一个公司的数据库部署还是待用单点部署,那若是宕机或是机器被损坏则是多糟糕的事情呀. 主从复制的部署方式为下图 主从复制是一个简单的数据库同步备份集群技术.这样的方式简 ...
- 离散化求RECT1
本文转载至点击打开链接 #include<stdio.h> struct node{ int x1,y1,x2,y2,c; }; struct node s[1010]; int px[2 ...
- js如何生成[n,m]的随机数(整理总结)
js如何生成[n,m]的随机数(整理总结) 一.总结 一句话总结: // max - 期望的最大值 // min - 期望的最小值 parseInt(Math.random()*(max-min+1) ...
- HDU 4372 Count the Buildings
Count the Buildings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- apidoc接口文档的快速生成
官方文档连接:http://apidocjs.com/#demo apidoc是一个轻量级的在线REST接口文档生成系统,支持多种主流语言,包括Java.C.C#.PHP和Javascript等.使用 ...
- C++包含头文件时尖括号和双引号区别
原文链接:http://c.biancheng.net/cpp/biancheng/view/66.html 如果你还看一些别的C++教程,那么你可能很早就发现了,有些书上的#include命令写作# ...
- $_FILES参数详解及简单<form>表单无刷新上传文件
$_FILES:经由 HTTP POST 文件上传而提交至脚本的变量,类似于旧数组$HTTP_POST_FILES 数组(依然有效,但反对使用)详细信息可参阅 POST方法上传 $_FILES数组内容 ...
- 应用层协议——HTTP
HTTP: Client HTTP <--> 应用程序HTTP报文 <--> Server HTTP 应用程序 由TCP支持 Statelessprotocol:不会记录客户端 ...
- java.sql.SQLException:错误 The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.
错误 方法 添加后面的内容即可