Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method description and example usage of defining function by JavaScript

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "the method description of JavaScript defining function and the usage of examples". In the operation of actual cases, many people will encounter this dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Method description

1. There are two ways to define a function: function declaration and function expression.

2. There is no need to name the function when using the function expression, so as to realize dynamic programming, that is, anonymous function. With anonymous functions, the JavaScript function is more useful.

Example

Insert title here/*I summary: 1. Function names can be used as variables, can be assigned, and can be passed a value of 2. Function name as a parameter, passed to another function * / = two ways of defining a function in js and function variable assignment = / / defining a function in javascript can be understood as defining a variable in / / js when the variable is weakly typed. / /-1//function add1 () {/ / alert ("add1"); / /} / / then the function, as a variable, can be used as an argument, and the add1 points to the first address var add1=new Function ("alert ('add1');") that the code block stores in memory. / /-2Compact / above 1Power2 is completely equivalent. It is the two ways of declaring a function in js / / in fact, it is add1 that points to this block of function code and stores the first address in memory. / / as for how to store, stack or stack, there is no more research here. The var addtt=add1;// function name can be used as a variable, it can be assigned or the value / addtt points to the function body addtt (); / / two ways to define the function in js and function variable assignment = / / = pass the function variable as a parameter = = / / basic format: function add2 (fun) {/ / pass the function name as an argument fun ();} add2 (add1) / /-- / / function names are used as parameters, and function add (a) {return name10;} / a: numbers, fun: function function addTest (a fun) {var t=fun (a); return t;} var tt=addTest (22 add); / / such writing is also ok alert (tt) / / = pass function variables as parameters = "JavaScript method description and instance usage of defining functions" is introduced here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report