This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.beget = (function(Function){ | |
return function(Object){ | |
Function.prototype = Object; | |
return new Function; | |
} | |
})(function(){}); | |
/* | |
It's a killer! Pity how almost no one uses it. | |
It allows you to "beget" new instances of any object, extend them, while maintaining a (live) prototypical inheritance link to their other properties. Example: | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Faux Console by Chris Heilmann http://wait-till-i.com */ | |
var ie = function() { | |
var v = 4, | |
//原作者的此处代码是3,考虑了IE5的情况,我改为4。 | |
div = document.createElement('div'), | |
i = div.getElementsByTagName('i'); | |
do { | |
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->'; | |
} while (i[0]); | |
return v > 5 ? v : false; //如果不是IE,之前返回undefined,现改为返回false。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scroll: function(start, end) { // 是否在滚动的标志位 | |
var _scroll = false; // 初始化获取滚动的高度 | |
var _top = $(document).scrollTop(); // 监听滚动是否开始结束 | |
var _scroll = setInterval(function() { | |
var __top = $(document).scrollTop(); | |
if (!_scroll && _top != __top) { // 滚动开始 | |
_scroll = true; | |
if (typeof start == 'function') start(); | |
} | |
if (_scroll && _top == __top) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var fs = require('fs'); | |
http.get('http://25.media.tumblr.com/tumblr_m98u7dXTPQ1qz7hmlo1_500.jpg',function (res) { | |
console.log(res.statusCode); | |
console.log(JSON.stringify(res.headers)); | |
var imgdata = ""; | |
res.setEncoding('binary'); | |
res.on('data',function (chunk) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// demo: http://jsfiddle.net/ShUW2/2/ | |
var P = Backbone.View.extend({ | |
events: { | |
'click p': 'p', | |
'change #a': 'change', | |
'click #s': 'click' | |
}, | |
p: function (e) { | |
alert('clicked the p'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--demo from : http://www.cnblogs.com/rubylouvre/archive/2012/10/18/2729388.html --> | |
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>onbeforeactivate by 司徒正美</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<script> | |
window.onload = function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//方法调用模式 | |
var obj = { | |
val: 0, | |
inc: function(i) { | |
this.val += i; | |
} | |
}; | |
console.log(obj.val); | |
obj.inc(2); | |
obj.inc(2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSON 字面量 | |
>>> ({"a":"\a"}) | |
Object { a="a"} | |
>>> ({"a":"\\a"}) | |
Object { a="\a"} | |
>>> ({"a":"\\\a"}) | |
Object { a="\a"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.bind_a = function() { | |
var method = this, | |
slice = Array.prototype.slice, | |
args = slice.apply(arguments), | |
obj = args.shift(); | |
return function() { | |
var arg = slice.apply(arguments); | |
return method.apply(obj,args.concat(arg)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
http = require('http'); | |
var Promise = function(values) { | |
this._callbacks = []; | |
this._errbacks = []; | |
if (arguments.length > 0) { | |
this.fulfill.apply(this, values); | |
} | |
} |
OlderNewer