下面是一段JS代码
我的水平很低,想知道怎么修改能让脚本语言javascript显示,谢谢各位高手的赐教!!!
//**********************************************************
// Core Functions
//**********************************************************
//----------------------------------------------------------
// Clone an object/array
//----------------------------------------------------------
// Don't use Object.prototype to pollute object data array
function $clone(obj){ if(typeof obj != "object") return obj; var newObj; if(obj instanceof Array){
// Clone Array
newObj = [];
for(var i=0; i<obj.length; i++){
if(typeof obj[i] == "object"){
newObj[i] = $clone(obj[i]);
}else{
newObj[i] = obj[i];
}
}
}else{
// Clone Object
newObj = {};
for(i in obj){
if(typeof obj[i] == "object"){
newObj[i] = $clone(obj[i]);
}else{
newObj[i] = obj[i];
}
}
} return newObj;}
//----------------------------------------------------------
// Extend an object if property not exist yet
//----------------------------------------------------------
function $extend(objTarget, objAdd, forceOverride){ var obj = $clone(objTarget); // always new, no pollution if(typeof obj != "object") return obj; for(var item in objAdd){
if(obj[item] == undefined || forceOverride) obj[item] = objAdd[item];
} return obj;}
//----------------------------------------------------------
// Convert Object to JSON String
//----------------------------------------------------------
function $toJSON(obj, param){ // paramters
var defaultParam = {
'indent': 0,
'indentText': '',
'delimiter': '',
'includeFunction': false
}; param = param ? $extend(param, defaultParam) : defaultParam; //execute
var indentString = '';
var prevIndentString = ''; if(param['indentText'] != ''){
param['indent']++;
prevIndentString = new Array(param['indent']).join(param['indentText']);
indentString = new Array(param['indent']+1).join(param['indentText']);
} switch(typeof(obj)){ case "object": if(obj instanceof Array){ var out = [];
for(var i=0; i<obj.length; i++){
var t = $toJSON(obj[i], param);
if(t){
out.push(indentString + t);
}
} out = "[" +
param["delimiter"] +
out.join("," + param["delimiter"]) +
param["delimiter"] +
prevIndentString + "]"; }else if(obj instanceof Date){ return "new Date(" +
obj.getFullYear() + "," + obj.getMonth() + "," + obj.getDate() + "," +
obj.getHours() + "," + obj.getMinutes() + "," + obj.getSeconds() + "," + obj.getMilliseconds() +
")"; }else if(obj instanceof Object){ var out = [];
for(label in obj){
var l = $toJSON(label);
var t = $toJSON(obj[label], param);
if(t){
out.push(indentString + l + ": " + t);
}
} out = "{" +
param["delimiter"] +
out.join("," + param["delimiter"]) +
param["delimiter"] +
prevIndentString + "}"; } break; case "string": var str = obj;
str = str.replace(/\\"/g, '\\\\"');
str = str.replace(/\r/g, '\\r');
str = str.replace(/\t/g, '\\t');
str = str.replace(/\n/g, '\\n');
str = str.replace(/\f/g, '\\f');
str = str.replace(/\"/g, '\\"'); out = '"' + str + '"';
break; case "number": out = isFinite(obj) ? String(obj) : 'null';
break;
我的水平很低,想知道怎么修改能让脚本语言javascript显示,谢谢各位高手的赐教!!!
//**********************************************************
// Core Functions
//**********************************************************
//----------------------------------------------------------
// Clone an object/array
//----------------------------------------------------------
// Don't use Object.prototype to pollute object data array
function $clone(obj){ if(typeof obj != "object") return obj; var newObj; if(obj instanceof Array){
// Clone Array
newObj = [];
for(var i=0; i<obj.length; i++){
if(typeof obj[i] == "object"){
newObj[i] = $clone(obj[i]);
}else{
newObj[i] = obj[i];
}
}
}else{
// Clone Object
newObj = {};
for(i in obj){
if(typeof obj[i] == "object"){
newObj[i] = $clone(obj[i]);
}else{
newObj[i] = obj[i];
}
}
} return newObj;}
//----------------------------------------------------------
// Extend an object if property not exist yet
//----------------------------------------------------------
function $extend(objTarget, objAdd, forceOverride){ var obj = $clone(objTarget); // always new, no pollution if(typeof obj != "object") return obj; for(var item in objAdd){
if(obj[item] == undefined || forceOverride) obj[item] = objAdd[item];
} return obj;}
//----------------------------------------------------------
// Convert Object to JSON String
//----------------------------------------------------------
function $toJSON(obj, param){ // paramters
var defaultParam = {
'indent': 0,
'indentText': '',
'delimiter': '',
'includeFunction': false
}; param = param ? $extend(param, defaultParam) : defaultParam; //execute
var indentString = '';
var prevIndentString = ''; if(param['indentText'] != ''){
param['indent']++;
prevIndentString = new Array(param['indent']).join(param['indentText']);
indentString = new Array(param['indent']+1).join(param['indentText']);
} switch(typeof(obj)){ case "object": if(obj instanceof Array){ var out = [];
for(var i=0; i<obj.length; i++){
var t = $toJSON(obj[i], param);
if(t){
out.push(indentString + t);
}
} out = "[" +
param["delimiter"] +
out.join("," + param["delimiter"]) +
param["delimiter"] +
prevIndentString + "]"; }else if(obj instanceof Date){ return "new Date(" +
obj.getFullYear() + "," + obj.getMonth() + "," + obj.getDate() + "," +
obj.getHours() + "," + obj.getMinutes() + "," + obj.getSeconds() + "," + obj.getMilliseconds() +
")"; }else if(obj instanceof Object){ var out = [];
for(label in obj){
var l = $toJSON(label);
var t = $toJSON(obj[label], param);
if(t){
out.push(indentString + l + ": " + t);
}
} out = "{" +
param["delimiter"] +
out.join("," + param["delimiter"]) +
param["delimiter"] +
prevIndentString + "}"; } break; case "string": var str = obj;
str = str.replace(/\\"/g, '\\\\"');
str = str.replace(/\r/g, '\\r');
str = str.replace(/\t/g, '\\t');
str = str.replace(/\n/g, '\\n');
str = str.replace(/\f/g, '\\f');
str = str.replace(/\"/g, '\\"'); out = '"' + str + '"';
break; case "number": out = isFinite(obj) ? String(obj) : 'null';
break;
解决方案 »
- 向远程消息队列发消息
- 跪求 google suggest 仿写代码
- 关于web后台角色权限管理的问题
- 远程关闭resin
- 我最近用jsp+mysql+tomcat做了个综合性质的网站但是不知道如何配置linux下的远服务器!(注:服务器上要对apache进行设置)请哥哥们帮帮我
- 求助;webservice编写服务器端?
- 有关《工厂设计模式》的一个问题!跪求答案!!谢谢啦!!
- 在线求助,急!!!!
- 为什么我安装完 weblogic 7.0 之后 http://localhost:7001/console 怎么运行不了呀
- 关于el表达式
- 下面是一段JS代码
- 请教:如何用XML&Java 编写email模板和地址簿?
我的水平很低,想知道怎么修改能让脚本语言javascript显示,谢谢各位高手的赐教!!!
//**********************************************************
// Core Functions
//**********************************************************
//----------------------------------------------------------
// Clone an object/array
//----------------------------------------------------------
// Don't use Object.prototype to pollute object data array
function $clone(obj){ if(typeof obj != "object") return obj; var newObj; if(obj instanceof Array){
// Clone Array
newObj = [];
for(var i=0; i<obj.length; i++){
if(typeof obj[i] == "object"){
newObj[i] = $clone(obj[i]);
}else{
newObj[i] = obj[i];
}
}
}else{
// Clone Object
newObj = {};
for(i in obj){
if(typeof obj[i] == "object"){
newObj[i] = $clone(obj[i]);
}else{
newObj[i] = obj[i];
}
}
} return newObj;}
//----------------------------------------------------------
// Extend an object if property not exist yet
//----------------------------------------------------------
function $extend(objTarget, objAdd, forceOverride){ var obj = $clone(objTarget); // always new, no pollution if(typeof obj != "object") return obj; for(var item in objAdd){
if(obj[item] == undefined || forceOverride) obj[item] = objAdd[item];
} return obj;}
//----------------------------------------------------------
// Convert Object to JSON String
//----------------------------------------------------------
function $toJSON(obj, param){ // paramters
var defaultParam = {
'indent': 0,
'indentText': '',
'delimiter': '',
'includeFunction': false
}; param = param ? $extend(param, defaultParam) : defaultParam; //execute
var indentString = '';
var prevIndentString = ''; if(param['indentText'] != ''){
param['indent']++;
prevIndentString = new Array(param['indent']).join(param['indentText']);
indentString = new Array(param['indent']+1).join(param['indentText']);
} switch(typeof(obj)){ case "object": if(obj instanceof Array){ var out = [];
for(var i=0; i<obj.length; i++){
var t = $toJSON(obj[i], param);
if(t){
out.push(indentString + t);
}
} out = "[" +
param["delimiter"] +
out.join("," + param["delimiter"]) +
param["delimiter"] +
prevIndentString + "]"; }else if(obj instanceof Date){ return "new Date(" +
obj.getFullYear() + "," + obj.getMonth() + "," + obj.getDate() + "," +
obj.getHours() + "," + obj.getMinutes() + "," + obj.getSeconds() + "," + obj.getMilliseconds() +
")"; }else if(obj instanceof Object){ var out = [];
for(label in obj){
var l = $toJSON(label);
var t = $toJSON(obj[label], param);
if(t){
out.push(indentString + l + ": " + t);
}
} out = "{" +
param["delimiter"] +
out.join("," + param["delimiter"]) +
param["delimiter"] +
prevIndentString + "}"; } break; case "string": var str = obj;
str = str.replace(/\\"/g, '\\\\"');
str = str.replace(/\r/g, '\\r');
str = str.replace(/\t/g, '\\t');
str = str.replace(/\n/g, '\\n');
str = str.replace(/\f/g, '\\f');
str = str.replace(/\"/g, '\\"'); out = '"' + str + '"';
break; case "number": out = isFinite(obj) ? String(obj) : 'null';
break;