Skip to content

Instantly share code, notes, and snippets.

View Janking's full-sized avatar

Janking Janking

View GitHub Profile
@Janking
Janking / gist:757f1692a6a40b64b2b4
Last active August 29, 2015 14:21
javascript AOP
<script type="text/javascript">
//所谓AOP
//在执行B前先执行A,
//执行完B后再执行C
Function.prototype.before = function(beforefn){
var __self = this;
console.log(__self);
return function(){
beforefn.apply(this,arguments);
return __self.apply(this,arguments);
//函数节流
var throttle = function (fn,interval){
var __self = fn,
timer,
firstTime = true;
var fun = function(){
var args = arguments,
__me = this,
outerTime = firstTime;
var timeChunk = function(ary,fn,count){
var obj,t;
var len = ary.length;
var start = function(){
for(var i = 0 ;i<Math.min(count || 1 , ary.length);i++){
var obj = ary.shift();
fn(obj);
}
};
return function(){
@Janking
Janking / gist:464283d537084491b457
Last active August 29, 2015 14:21
惰性单例模式
//惰性单例模式
<a href="javascript:;" id="btn1">1111111</a>
<br>
<br>
<br>
<br>
<br>
<a href="javascript:;" id="btn2">2222222</a>
@Janking
Janking / gist:5c9997fbf334e1b09103
Created May 26, 2015 14:03
传统单例模式
//传统单例模式
var Singleton = function(name){
this.name = name;
this.instance = null;
}
Single.prototype.getName = function(){
console.log(this.name);
};
Singleton.getInstance = function(name){
@Janking
Janking / cacheProxy.js
Last active December 4, 2015 07:36
缓存代理模式
var mult = function() {
console.log('开始计算乘积:');
var a = 1;
for (var i = 0, l = arguments.length; i < l; i++) {
a = a * arguments[i];
}
return a;
}
var sum = function(a,b){
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="" id="form">
@Janking
Janking / file.md
Last active August 29, 2015 14:22
Four Ways To Do Pub/Sub With jQuery

#Four Ways To Do Pub/Sub With jQuery and jQuery UI (in the future)

Between jQuery 1.7 and some of work going into future versions of jQuery UI, there are a ton of hot new ways for you to get your publish/subscribe on. Here are just four of them, three of which are new.

(PS: If you're unfamiliar with pub/sub, read the guide to it that Julian Aubourg and I wrote here http://msdn.microsoft.com/en-us/scriptjunkie/hh201955.aspx)

##Option 1: Using jQuery 1.7's $.Callbacks() feature:

$.Callbacks are a multi-purpose callbacks list object which can be used as a base layer to build new functionality including simple publish/subscribe systems. We haven't yet released the API documentation for this feature just yet, but for more information on it (including lots of examples), see my post on $.Callbacks() here:

@Janking
Janking / index.html
Created June 1, 2015 16:02
pubsub模式-【典型版】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
@Janking
Janking / proxy.html
Created June 9, 2015 14:39
代理模式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
var arr = [
'http://e.hiphotos.baidu.com/image/pic/item/e61190ef76c6a7ef023c23e9fffaaf51f2de66e3.jpg',
'http://b.hiphotos.baidu.com/image/pic/item/c83d70cf3bc79f3df9df6fffb8a1cd11738b29c6.jpg',