This article mainly introduces the JS function definition functions of several methods, the need for friends can refer to the
4 ways to define functions for JS function 1. The most basic function declared as a Benbon is used. The code is as follows: function func () {} or var func=function () {}; 2. Use as a class constructor: code is as follows: function class () {} class.prototype={}; var item=new class (); 3. Use as closures: code as follows: (function () {//Standalone scope}) (); 4. Can be used as a selector: The code is as follows: Var addevent=new function () {if (!-[1,]) return function (Elem,type,func) {attachevent (Elem, ' on ' +type , func);}; else return function (Elem,type,func) {AddEventListener (elem,type,func,false);} };//avoids repeated judgments 5. The mixed application of the above four cases: the code is as follows: Var class=new function () {var privatearg;//static private variable function privatemethod=function () {};//static Private method return function () {*/* true constructor *