javascript curry

Function.prototype.before = function (func) {
	var me = this;
	return function () {
		if (func.apply(this, arguments) === false) {
			return false;
		}
		return me.apply(this, arguments);
	}
}

// 先执行func
Function.prototype.before2 = function (func) {
	var me = this;
	return function () {
		var ret = func.apply(this, arguments);

		if (!ret) {
			return false;
		} 

		return me.apply(this, arguments);
	}
}

// 先执行 after,再执行func
Function.prototype.after = function (func) {
	var me = this;
	return function () {
		var ret = me.apply(this, arguments);

		if (ret == false) {
			return false;
		}

		func.apply(this, arguments);
		return ret;
	}
}

var bind  = function (fn, context) {
	return function () {
		return fn.apply(context, arguments)
	}
};


var curry = function (fn) {
	var args = Array.prototype.slice.call(arguments, 1);
	return function () {
		var innerArgs = Array.prototype.slice.call(arguments);
		var finalArgs = args.contact(innerArgs);
		return fn.apply(null, finalArgs);
	}
};

var bind2 = function (fn, context) {
	var args = Array.prototype.slice.call(arguments, 2);
	return function () {
		var innerArgs = Array.prototype.slice.call(arguments);
		var finalArgs = args.contact(innerArgs);
		return fn.apply(context, finalArgs);
	}
}
posted @ 2013-06-03 11:55  leamiko  阅读(248)  评论(0编辑  收藏  举报
document.getElementById('MySignature') && document.getElementById('MySignature').style.display = "none"; document.getElementById('MySignature') && document.getElementById('blog_post_info').style.display = "none";