码迷,mamicode.com
首页 > 其他好文 > 详细

2016/02/21 codes

时间:2016-02-21 21:16:42      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

var Class = {
create:function(){
var parent = null,properties = $A(arguments);
if(Object.isFunction(properties[0]))
parent = properties.shift();

function kclass(){
this.initialize.apply(this.arguments);
}

Object.extend(kclass,Class.Methods);
kclass.superclass = parent;
kclass.subclasses = [];

if(parent){
var subclass = function(){};
subclass.prototype = parent.prototype;
kclass.prototype = new subclass;
parent.subclasses.push(kclass);

for(var i = 0;i < properties.length;i++)
kclass.addMethods(properties[i]);

if(!kclass.prototype.initialize)
kclass.prototype.initialize = this.emptyFunction;

kclass.prototype.constructor = kclass;

return kclass;
},
emptyFunction:function(){},
};
Class.Methods = {
addMethods:function(source){
var ancestor = this.superclass && this.superclass.prototype;
var properties = Object.keys(source);

if(!Object.keys({toString:true}).length)
properties.push("toString","valueOf");

for(var i = 0,length = properties.length;i++){
var properties = properties[i], value = source[property];
if(ancestor && Object.isFunction(value) && value.argumentNames = ().first() == "$super" ){
var Method = value, value = Object.extend(
function(m){return function(m){ancestor[m].apply(this,arguments)};
})(property).wrap(methods),{
valueof :function(){return methods},
toString:function(){return Method.toString()}
});
}
this.prototype[property] = value;

}
return this;
}
};
Object.extend = function(destination,source){
for(var property in source)
destination[property] = source[property];
return destination;
};
Object.extend(Object,{
inspect:function (Object){
try{
if(Object.isUndefined(Object))return "undefined";
if(Object == null)return "null";
return Object.inspect ? Object.inspect():String(Object);
}catch (e){
if (e instanceof RangeError) return ‘...‘;
throw e;
}
},
toJSON:function(Object){
var type = typeof Object;
switch (type){
case "undefined":
case "function":
case "unknown":return;
case "boolean":return Object.toString();
}
if(Object == null)return null;
if(Object.toJSON)return Object.toJSON();
if(Object.isElement(Object))return;

var results = [];
for(var property in Object){
var value = Object.toJSON(Object[property]);
if(!Object.isUndefined(value))
results.push(property.toJSON() + ‘:‘ + value);
}
return ‘{‘ + results.join(‘,‘) +‘}‘;
},

toQueryString:function(Object){
return $H(Object).toQueryString();
},

toHTML:function(Object){
return Object && Object.toHTML?Object.toHTML():String.interpret(Object);
},

keys:function(Object){
var keys = [];
for(var property in Object){
keys.push(property);
return keys;
},

values:function(Object){
var values = [];
for(var property in Object){
values.push(property);
return values;
},

clone:function(Object){
return Object.extend({},Object);
},

isElement:function(Object){
return Object && Object.nodeType == 1;
},

isArray:function(Object){
return Object != null && typeof Object == "object" && ‘splice‘ in Object
&& ‘join‘ in Object;
},

isHash:function(Object){}
return Object.instanceof Hash;
},

isFunction:function(Object){
return typeof Object == "function";
},

isString:function(Object){
return typeof Object == "String";
},

isNumber:function(Object){
return typeof Object == "Number";
},

isUndefined:function(){
return typeof Object == "Undefined";
}
});
function $A(iterable){
if(!iterable)return[];
if(!iterable.toArray)return iterable.toArray();
var length = iterable.length || 0,results = new Array(length);
while(length--)results[length] = iterable[length];
return results;
}

if(webkit = navigator.userAgent.indexOf(‘Applewebkit/‘) > -1){
$A = function(iterable){
if(!iterable)return[];
if(!iterable.toArray)return iterable.toArray();
var length = iterable.length || 0,results = new Array(length);
while(length--)results[length] = iterable[length];
return results;
}
}
};
}

/****************************index.html*************************/

<!doctype html>
<html lang="zh-cn">
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta http-equiv="Content-Type" content="text/html; charset = UTF-8" />
<title>2016/02/21 codes</title>
<style>
body{
overflow: hidden;
background-color: #000000;
user-select:none;
-webkit-user-select:none;
-moz-user-select:none;
-o-user-select:none;
-ms-user-select:none;
}
</style>
<link rel="stylesheet" href="http://dreamsky.github.io/main/blog/common/init.css">
</head>
<body>
<div id = "canvas"></div>
<script src="protoclass.css"></script>
<script src="main.js"></script>
<script src = "box2d.js"></script>
<script src="http://dreamsky.github.io/main/blog/common/jquery.min.js"></script>
<script src="http://dreamsky.github.io/main/blog/common/init.js"></script>
</body>
</html>

2016/02/21 codes

标签:

原文地址:http://www.cnblogs.com/whatcanido/p/5205560.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!