燃烧脑细胞时间

作者:手气不错 发布时间:February 27, 2008 分类:JavaScript

烧脑细胞时间,请分别说明下述代码的输出。

代码一

var hello = new function() {
    return "hello, world!"
}; 
alert(hello);

代码二

function hello() {
    return "hello, world!";
}
var hello_sample = new hello();
alert(hello_sample);

代码三

var hello = new function() {
    return new String("hello, world!")
};
alert(hello);

代码四

var hello = new function() {
    return function() {
        return 'hello, world!';
    };
};
alert(hello);

代码五

var hello = function() {return "hello, world!"}();
alert(hello);

可以参考 怿飞 Blog 上的一篇文章

已有 3 条回复

  1. DELLA August 24th, 2009 at 04:24 pm #1
    DELLA

    怿飞的文章貌似被删掉了

  2. DELLA August 25th, 2009 at 04:41 pm #2
    DELLA

    http://www.planabc.net/2008/02/20/javascript_new_function/ 可能是路径改掉了

  3. Function August 25th, 2009 at 05:19 pm #3
    Function

    [...]在网上看到两篇文章燃烧脑细胞时间和详解new function(){}和function(){}()记录下以加深映像;[...]

Yahoo 统计