Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cuixiping/3141209 to your computer and use it in GitHub Desktop.
Save cuixiping/3141209 to your computer and use it in GitHub Desktop.
最简计算星座等3个函数
// 根据生日的月份和日期,计算星座。 http://blog.csdn.net/cuixiping/
function getAstro(m,d){
return "魔羯水瓶双鱼牡羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯".substr(m*2-(d<"102223444433".charAt(m-1)- -19)*2,2);
}
//下面写一个测试函数
function test(m,d){
document.writeln(m+"月"+d+"日 "+getAstro(m,d));
}
//测试
test(12,21); //输出: 12月21日 射手
test(12,22); //输出: 12月22日 魔羯
test(1,1); //输出: 1月1日 魔羯
test(2,18); //输出: 2月18日 水瓶
test(2,19); //输出: 2月19日 双鱼
//把Util在闭包里进行定义
( function() {
var fns = [],ta;
window.Util = function (a){
ta=typeof a;
if(ta==='number'){
if(a>0){
if(fns[a-1]){
return fns[a-1].apply(window, Array.prototype.slice.call(arguments,1));
}
}else{
delete fns[-a-1];
}
}else if(ta==='function'){
return fns.push(a);
}
};
}());
/** 用法 ************
// 注册
var fnId = Util( function( msg ) {
alert( msg );
} );
// 调用
Util( fnId, 'Hello, World' ); //-> 'Hello, World';
// 销毁,在id前面加上负号
Util( - fnId);
// 销毁后调用,无效果
Util( fnId, 'Hello, World' );
*******************/
var i = +new Date;
document.writeln(i); //1342690787841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment