JavaScript 轻松实现强大的Cookies操作

刚刚群里有人问到JavaScript的Cookies操作, 于是想到之前也写过一个, 刚刚一搜, 是去年8月份的事情了… 不过功能还算不错, 而且使用方便, 于是整理一下, 献上:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>

<html xmlns=””>
    <script src=”” type=”text/javascript”></script>
    <script src=”” type=”text/javascript”></script>
    <script type=”text/javascript”>
        cookies[String name] 获取cookies集合中名为name的Cookie的值.
        cookies.clear() 清除所有Cookie, 并更新cookies集合, 无返回值.
        cookies.del(String name) 删除相应名称的Cookie, 并更新cookies集合, 无返回值.
        cookies.del(Array names) 批量删除相应名称的Cookie, 并更新cookies集合, 无返回值.
        cookies.get(String name) 更新cookies集合, 获取相应名称的Cookie的值, 返回值为String.
        cookies.refresh() 更新cookies集合, 无返回值.
        cookies.set(String name, String value) 设置相应名称的Cookie的值, 并更新cookies集合, 无返回值.
        cookies.set(String name, String value, Date date) 设置相应名称的Cookie的值与过期时间, 并更新cookies集合, 无返回值.
        cookies.set(Array names, Array values) 批量设置相应名称的Cookie的值, 并更新cookies集合, 无返回值.

        if (cookies[“abc”] == undefined) {
            alert(“set cookie”);
            cookies.set(“abc”, “123”);




JavaScript 实现函数重载及类的多构造函数

这个是之前一篇 ( 的升级版, 添加了更强的对 “类” 的支持, 取消了Null类型, 顺便修正了一些bug.



/* 函数的用法 */

//这里也可以使用 var fn = _(); 创建空函数, 并在以后添加重载
var fn = _(function () {
    alert(“No arguments!”);

fn._(String, function (str) {
    alert(“You got me a string: ” + str + “.”);

fn._(String, Integer, function (str, n) {
    alert(“The string is: ” + str + “; and the integer is: ” + n + “.”);

fn(“test2”, 123);

/* 类的用法 */
var C = class_(function () {
    var x;

    this.getX = _(function () {
        return x;

    /* 也可无构造函数 */
    C._(Integer, function (i) {
        x = “Integer: ” + i;

    C._(String, function (s) {
        x = “String: ” + s;

var c1 = new C(“abc”);
var c2 = new C(123);


Vibot 2011.3.10

I don’t know if this moment should be called too late or too early…

After hours’ work, I have finally made the outline-searching algorithm for a formatted map. I know it cannot be called difficult to many programmers, even not for me. But the feelings are good, cause I don’t write this kind of code usually.

I thought about how to find the right route efficiently for sometime, and came out with this solution. Firstly find the possible part of the whole outline, and… enumerate every point on it… I don’t really like enumeration, cause it always means inefficiency. But sometimes you know, It’s unavoidable.

So, I really need to go to sleep now.

Hope me a nice day after waking up!

Vibot 2011.3.7

I formally started my robot project today. And when I was about to write this post, I got the project a temporary name, Vibot.

I don’t have a very good skill on algorithm, so I am beginning with a relatively simple thing — find an available route on a formatted map. I have thought for a while, and come out with a seemly simple solution. I’ve no idea if it will be easy to make it via CODE…

And by the way, I really think the most useful skill on mathematic for these kinds of algorithms is Geometry.

Best wishes to myself!