Four methods of JS function call: method calling mode, function calling mode, constructor calling mode, apply, call calling mode
1. Method calling mode:
First define an object, then define a method in the object's properties, and execute the method through myobject.property. This refers to the current myobject object.
var blogInfo={ blogId:123, blogName:"werwr", showBlog:function(){alert(this.blogId);}};blogInfo.showBlog();2. Function call mode
Define a function and set a variable name to save the function. At this time, this points to the window object.
var myfunc = function(a,b){ return a+b;}alert(myfunc(3,4));3. Constructor call mode
Define a function object, defines properties in the object, and defines methods in its prototype object. When using prototype's method, the object must be instantiated to call its methods.
var myfunc = function(a){ this.a = a;};myfunc.prototype = { show:function(){alert(this.a);}}var newfunc = new myfunc("123123123");newfunc.show();4. apply, call mode
var myobject={};var sum = function(a,b){ return a+b;};var sum2 = sum.call(myobject,10,30); //var sum2 = sum.apply(myobject,[10,30]); alert(sum2);The above JS function definition and calling method recommendation is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.