JS函数的写法

1、普通函数

function fun1(){

  console.log("this is first function");

}

2、匿名函数

var fun = function(){

  console.log("this is second function");

}

匿名函数的调用方法:

fun();

还有两种调用匿名函数的方法:

(function(){

console.log("this is first call")}());

(function(){

console.log("this is second call"){})();

3、对象方法

var obj={

func:function(){

console.log("this is third function)

}

};

调用:

obj.func();

4、构造函数的方法

var funObj =function(){};

funObj.prototype.func=function(){

  console.log("this is forth function");

}

调用:

var objFun = new funObj();

objFun.func();

posted @ 2017-07-08 22:42  吹牛不要本钱  阅读(303)  评论(0)    收藏  举报