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 ...
随机推荐
- OpenJDK源码研究笔记(九)-可恨却又可亲的的异常(NullPointerException)
可恨的异常 程序开发过程中,最讨厌异常了. 异常代表着程序出了问题,一旦出现,控制台会出现一屏又一屏的堆栈错误信息. 看着就让人心烦. 对于一个新人来讲,遇到异常经常会压力大,手忙脚乱,心生畏惧. 可 ...
- etTimeout来实现setInterval
etTimeout来实现setInterval <script type="text/javascript"> function interval(func, w, t ...
- 【转】 HTML解析:基于XPath的C#类库HtmlAgiliytyPack
[转] HTML解析:基于XPath的C#类库HtmlAgiliytyPack 最近处于毕业设计开始阶段,前期工作需要去国外的一些专业数据库网站比对一些所需TF家族信息,为了快捷方便,想到用程序去帮助 ...
- poj2002 哈希
Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 17666 Accepted: 6735 Descript ...
- 基于matlab的音频波形实时採集显示 v0.1
robj = audiorecorder(44100,16,1); %设置採样频率.採样位数.通道数 recordblocking(robj,1); %採集初步数据(1s长度) rdata = get ...
- php 读取windows 的系统版本,硬盘,内存,网卡,数据流量等
php 读取windows 的系统版本,硬盘,内存,网卡,数据流量等 <?php header("Content-type: text/html; charset=utf-8" ...
- P3507 [POI2010]GRA-The Minima Game
题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...
- 实现图片懒加载(lazyload)
对页面加载速度影响最大的就是图片,一张普通的图片可以达到几M的大小,而代码也许就只有几十KB.当页面图片很多时,页面的加载速度缓慢,几S钟内页面没有加载完成,也许会失去很多的用户. 所以,对于图片过多 ...
- javascript“类”与继承总结
http://haorooms.com/post/js_jc_lei2
- 微信小程序官方文档中的加密算法
用Nodejs来算一下: