<!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的更多相关文章

  1. 前端试题本(Javascript篇)

    JS1. 下面这个JS程序的输出是什么:JS2.下面的JS程序输出是什么:JS3.页面有一个按钮button id为 button1,通过原生的js如何禁用?JS4.页面有一个按钮button id为 ...

  2. RFID-RC522、FM1702SL、M1卡初探

    catalogue . 引言 . RC522芯片(读卡器)简介 . FM1702SL芯片(读卡器)简介 . RFID M1卡简介 . 读取ID/序列号(arduino uno.MFRC522芯片 Ba ...

  3. CentOS6.5安装MySql5.5

    最近在CentOS上安装MySql,本来以为yum安装会很简单,但是却花了自己不少时间,所以决定和大家分享下. 首先,安装MySql源! 下载地址:http://dev.mysql.com/downl ...

  4. Bad Hair Day【单调栈】

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAzMAAANgCAIAAACX06G4AAAgAElEQVR4Aey9e5RlW13fuw40HORxfI ...

随机推荐

  1. Unity C# 设计模式(一)单例模式

    动机(Motivation):    在软件系统中,经常有这样一些特殊的类,必须保证它们在系统中只存在一个实例,才能确保它们的逻辑正确性.以及良好的效率 意图:    保证一个类仅有一个实例,并提供一 ...

  2. HDU 4309 Seikimatsu Occult Tonneru

    Seikimatsu Occult Tonneru Time Limit: 6000ms Memory Limit: 32768KB This problem will be judged on HD ...

  3. Spring Cloud学习笔记【九】配置中心Spring Cloud Config

    Spring Cloud Config 是 Spring Cloud 团队创建的一个全新项目,用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持,它分为服务端与客户端两个部分.其中服务端 ...

  4. SDSoC使用体验

    本文作者:卜居 转载请保留作者信息.原文网址(http://blog.csdn.net/kkk584520/article/details/47220575). 本文project可到我的资源下载(h ...

  5. CSS3 实现RSS图标

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>CSS3 实现RSS图标&l ...

  6. Linux 内核源码(kernel source)

    查看内核的发行版:uname -r(--kernel-release) $ uname -r 4.4.0-78-generic 内核源码所在的位置:/usr/src $ cd /usr/src $ l ...

  7. Semi-Prime(半素数)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2723 Semi-Prime Time Limit: 2 Seconds   ...

  8. 利用 urandom 生成随机密码

    cat /dev/urandom | LC_ALL=C tr -dc "[:alnum:]" | fold -w 16 |head -3   说明: fold -w 16  指定密 ...

  9. Server.UrlEncode与HttpUtility.UrlEncode的区别

    一.HttpUtility.UrlEncode 方法 1.public static string UrlEncode(byte[]) 将字节数组转换为已编码的 URL 字符串. 2.public s ...

  10. "getElementsByClassName is not a function" 报错原因

    element.getElementsByClassName(""): 返回的含有该类的子元素数组,除了子元素以外的后代元素是获取不到的.要遍历使用,或者.element.getE ...