《Javascript 语言精粹》 中 用到的一些代码 (1)

var isNumber = function isNumber(value){
    return typeof value === 'number' && isFinite(value);
}
------------------------------------------------------------------
var i;
var word;
var text = "This oracle of comfort has so pleased me, "+
        "That when I am in heaven I shall desire "+
            "To see whtat this child does, "+
            "and praise my Constructor.";

words = text.toLowerCase().split(/[\s,.]+/);
var count = {};
for(i=0;i<words.length;i++){
    word = words[i];
    if(count[word])
        count[word]+=1;
    else
        count[word]=1;
}

-----------------------------------------------------------------------
if(typeof Object.beget !== "function"){
    Object.beget = function(o){
        var F = function(){};
        F.prototype = o;
        return new F();
    }
}

-------------------------------------------------------------------------

var Foo = function(string){
    this.status = string;
};

Foo.prototype.get_status = function(){
    return this.status;
}
var myFoo = new Foo("hello_world");
alert(myFoo.get_status());
-------------------------------------------------------------------------

var statusObject = {
    "status":"OK"
}

var status = Foo.prototype.get_status.applay(statusObject);

 

posted @ 2014-06-04 17:30  NintendoBoy  阅读(128)  评论(0编辑  收藏  举报