燃烧脑细胞时间February 27, 2008

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

代码一

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 DELLA

    怿飞的文章貌似被删掉了

  2. DELLA DELLA

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

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

Yahoo 统计