⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extra.js

📁 在线生成手机二维码的源程序
💻 JS
📖 第 1 页 / 共 2 页
字号:
	var body = this.getbody();
	var list = [];
	body.replace(/var ([\w$]+)/g,function(){
		list.push(arguments[1])
	});
	return list;
}

// 関数名を変更する
Function.prototype.rename = function(name){
	var self = this;
	eval("var tmp = function "+name+"("+self.getargs().join(",")+")"+"{return self.apply(this,arguments)}");
	return tmp
}
// 引数名を変更する
Function.prototype.renameArgs = function(arg){
	var self = this;
	eval("var tmp = function " + self.getname() + "(" + arg.join(",")+")"+"{return self.apply(this,arguments)}");
	return tmp
}
// 関数を再構築する
Function.prototype.rebuild = function(){
	var self = this;
	return Function(
		self.getargs().join(","),
		self.getbody()
	);
}
// withで囲むように変形する
Function.prototype.rebuildWith = function(base){
	var self = this;
	var tmp  = new Function(
		self.getargs().join(","),
		"with(arguments.callee.__base__){" + self.getbody() + "}"
	);
	tmp.__base__ = base;
	return tmp;
}
/*
 callとapplyを上書きして別の関数が実行されるようにする
*/
Function.prototype.swap = function(func){
	this.call  = function(){return func.apply(arguments[0],arguments.toArray().slice(1))}
	this.apply = function(){return func.apply(arguments[0],arguments[1])}
	return this;
}
/*
 固定
*/
Function.prototype.applied = function(thisObj,args){
	var self = this;
	return function(){
		return self.apply(thisObj,args)
	}
}
Function.prototype.bindThis = function(thisObj){
	var self = this;
	return function(){
		return self.apply(thisObj,arguments)
	}
}



/*
 関数をその場所で宣言しなおす。
*/
Function.prototype.to_here = function(str){
	return "var str = " + this
}
/*
 その場でevalで評価するために変形する。
  bodyからreturn を削除。
  引数は返値を格納する変数を文字列で。
*/
Function.prototype.to_eval = function(re){
	var self = this;
	return "try{" 
		+ self.getbody().replace(/(function.*?\{[^}]*?\})|(return)/g,
			function(){return $1 ? $0 : "throw"}.replace_callback()
		)
		+ "}catch(e){"
		+ (re ? "var " + re + " = e" : "")
		+ "}"
}

/*
 AOP
*/
// 引数の加工
Function.prototype.addBefore = function(func){
	var self = this;
	return function(){
		var args = func(arguments);
		return (args) ? self.apply(this,args) : self.apply(this,arguments)
	}
}
// 返値の加工
Function.prototype.addAfter  = function(func){
	var self = this;
	return function(){
		var old_rv = self.apply(this,arguments);
		var result = func(old_rv,arguments);
		return (result) ? result : old_rv;
	}
}
// 関数を置き換える
Function.prototype.addAround = function(func){
	return function(){
		return func.apply(this,arguments);
	}
}


/*
 Number.prototype
  2005-09-15
*/
Number.prototype.isNumber = true;

function zerofill(keta){
	return function(){return ("0".x(keta) + this).slice(-keta)}
}
// 指定桁数になるよう0で埋めたstringを返す
Number.prototype.zerofill = function(keta){
	return ("0".x(keta) + this).slice(-keta)
}
// 文字列に変換する際の関数を指定する
Number.prototype.format = function(func){
	this.toString = func;
	return this;
}
/*
 Object.prototype

*/
Object.extend = function(destination, source) {
	for (property in source) {
		source.own(property) &&
			(destination[property] = source[property])
	}
	return destination;
}
Object.prototype.extend = function(object) {
  return Object.extend.apply(this, [this, object]);
}
/*
Object.prototype.own = function(key){
	return this.hasOwnProperty(key)
}
*/
Object.prototype.own = Object.prototype.hasOwnProperty;

Object.prototype.extend({
	forEach : function(callback,thisObject){
		for(var i in this)
			this.own(i) && callback.call(thisObject,this[i],i,this)
	},
	every : function(callback,thisObject){
		for(var i in this)
			if(this.own(i)){
				if(!callback.call(thisObject,this[i],i,this)) return false;
			}
		return true;
	},
	keys : function(){
		var tmp = [];
		for(var i in this) this.own(i) && tmp.push(i);
		return tmp;
	},
	values : function(){
		var tmp = [];
		for(var i in this) this.own(i) && tmp.push(this[i]);
		return tmp;
	},
	each : function(func){
		for(var i in this) this.own(i) && func(this[i],i,this)
	},
	map  : function(callback,thisObject){
		var tmp = {};
		for(var i in this)
			this.own(i) && (tmp[i] = callback.call(thisObject,this[i],i,this));
		return tmp
	},
	toArray : function(){
		var tmp = [];
		for(var i=0;i<this.length;i++) tmp[i] = this[i];
		return tmp;
	},
	loop : function(func){
		for(var i=0;i<this.length;i++){
			if(this.hasOwnProperty(i)) func(i,this[i],this)
		}
	}
});
Object.prototype.getClassName = function(){
	return this.constructor.getname();
}


/*
 RegExp.prototype
*/

RegExp.prototype.isRegExp = true;

RE = Regexp = RegExp;
RegExp.escape = function(str){
	return str.replace(/(\\|\[|\]|\(|\)|\{|\}|\^|\-|\$|\||\+|\*|\?|\.|\!)/g,"\\$1");
};

// よく使われる正規表現を高速化
RE.func_body = /\{((:?.|\n)*)\}/;
RE.func_name = /function ([\w$]+)/;
RE.func_args = /\(([^)]*)/;

function MatchData(){
	var self = this;
	this.leftContext = this.pre_match  = new LazyString(function(){
		return self.input.slice(0,self.index)
	});
	this.rightContext = this.post_match = new LazyString(function(){
		return self.input.slice(self.index+self.$0.length)
	});
	return this;
}
MatchData.prototype.update = function(a){
	this.lastMatch = this.$0 = a[0];
	this.match = this.captures = [];
	for(var i=1;i<a.length-2;i++){
		this.match.push(a[i]);
		this["$"+i] = a[i];
	}
	this.index = a[a.length-2];
	this.input = this.$_ = a[a.length-1];
}

// 関数をreplaceのcallbackとして使いやすいように
Function.prototype.replace_callback = function(thisObject){
	var self = this;
	var match = new MatchData();
	var newfunc = self.rebuildWith(match);
	return function(){
		match.update(arguments);
		return newfunc.call(thisObject)
	}
}



/*
 String.prorotype

*/
String.prototype.isString = true;
String.prototype.x = function(l){
	for(var i=0,tmp="";i<l;i++) tmp+=this;
	return tmp;
}
String.prototype.chars = function() { return(this.split("")) }
String.prototype.toRegExp = function(){
	return new RegExp(this);
}



// 遅延評価される数値
function LazyNumber(func){
	this.toString = function(base){
		return base ? (func()).toString(base) : func()
	};
	this.isLazy = true;
}
// 遅延評価される文字列
function LazyString(func){
	this.toString = func;
	this.length = new LazyNumber(function(){return func().toString().length});
	this.isLazy = true;
}
LazyString.methods = [
	"split","substr","substring","slice","concat","toUpperCase","toLowerCase",
	"search","match","replace","charAt","length"
];
(function(){
	var m = LazyString.methods;
	var mm = function(method){
		return function(){
			var tmp = this.toString();
			return tmp[method].apply(tmp,arguments)
		}
	}
	for(var i=0;i<m.length;i++){
		LazyString.prototype[m[i]] = mm(m[i]);
	}
})();
Function.prototype.bg = function(ms){
	this.PID = setInterval(this,ms);
	return this;
}
Function.prototype.kill = function(){
	clearInterval(this.PID)
}
/*
 var a = function(v){alert(v)};
 var b = a.later(100);
 b("testtest");
 b.cancel(); // cancel
 b.notify(); // do 
*/
Function.prototype.later = function(ms){
	var self = this;
	var func = function(){
		var arg = func.arguments;
		var apply_to = this;
		var later_func = function(){
			self.apply(apply_to,arg)
		};
		var PID = setTimeout(later_func,ms);
		return {
			cancel : function(){clearTimeout(PID)},
			notify : function(){clearTimeout(PID);later_func()}
		}
	};
	return func;
};
Function.prototype.wait = Function.prototype.later;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -