---
title: "神奇的JavaScript Function"
author: "pengfeng"
date: "2010-09-20T16:53:09Z"
tags: []
categories: ["Web前端"]
slug: "javascript-function"
draft: false
lastmod: "2010-09-20T16:53:09Z"
id: 768355
url: "https://pengfeng.iteye.com/blog/768355"
---

今天在看javascript面向对象方面的相关资料过程中发现一个非常有趣的问题,下面列出来了四种创建函数的方法及测试用例:

 

```
第一种: 

var a = function(){};
alert(a.prototype);//[object Object]

第二种:

var a = new function(){}; 
alert(a.prototype);//undefined

第三种:

var b = new Function(){};//此行代码出错
alert(b.prototype);

第四种:

var b = new Function();
alert(b.prototype);//[object Object]
```

 

疑惑: 

第二种写法在jquery tablesorter插件中有这样用,不明白和其他创建函数的方式有何区别

 

希望高手看见后能就以上各种创建函数的方式及其之间的区别进行指点迷津,如果我有答案后也会及时更新共享,谢谢