Skip to content

Instantly share code, notes, and snippets.

View hacke2's full-sized avatar
🐜
ant has power

hacke2 hacke2

🐜
ant has power
View GitHub Profile
@hacke2
hacke2 / size.js
Created October 15, 2014 01:24
位置与大小
var s;
s += " 屏幕分辨率的高:"+ window.screen.height+"\n";
s += " 屏幕分辨率的宽:"+ window.screen.width+"\n";
万能的js是这样干的 s += " 网页可见区域宽:"+ document.body.clientWidth+"\n";
s += " 网页可见区域高:"+ document.body.clientHeight+"\n";
s += " 网页可见区域宽:"+ document.body.offsetWidth + " (包括边线和滚动条的宽)"+"\n";
s += " 网页可见区域高:"+ document.body.offsetHeight + " (包括边线的宽)"+"\n";
s += " 网页正文全文宽:"+ document.body.scrollWidth+"\n";
s += " 网页正文全文高:"+ document.body.scrollHeight+"\n";
s += " 网页被卷去的高(ff):"+ document.body.scrollTop+"\n";
@hacke2
hacke2 / AOP.JS
Created November 7, 2014 03:23
js面向切面
Function.prototype.before = function(func) {
var that = this;
return function() {
//debugger
if(func.apply(this, arguments) === false) {
return false;
}
return that.apply(this, arguments);
}
}
function get(uri) {
return http(uri,'GET');
}
function post(uri,data) {
if(typeof data === 'object' && !(data instanceof String || (FormData && data instanceof FormData))) {
var params = [];
for(var p in data) {
if(data[p] instanceof Array) {
for(var i = 0; i < data[p].length; i++) {
params.push( encodeURIComponenet(p) + '[]=' + encodeURIComponenet(data[p][i]);
@hacke2
hacke2 / promise-sequence.js
Created September 10, 2015 09:49
promise sequence exec tasks
function sequenceTasks(tasks) {
function recordValue(results, value) {
results.push(value);
return results;
}
var pushValue = recordValue.bind(null, []);
return tasks.reduce(function (promise, task) {
return promise.then(task).then(pushValue);
}, Promise.resolve());
}