Javascript Learning (3) -- [basic review] Functions

Source: Internet
Author: User
To put it simply, I think it is not particularly difficult for my humble understanding of js functions. But if I focus on functions and other aspects in detail, so it really takes a little time and effort. Of course, this is a basic review, and I will briefly explain my understanding of js functions. If it is just a simple function, I think it is not particularly difficult, but it will take a little time and effort to focus on a series of peripheral functions. Of course, this is a basic review, let's simply talk about the basic application of the function. I still want to simply paste a few pieces of code to describe the basic usage of the function. After all, this blog is used to describe the design pattern of javascript advanced applications. So if you have any questions, you can use your own encyclopedia. [Javascript]/*** function */(function () {// function name (val1, val12, val3, valn) {// code // return //} // var fn = function () {// code //} // difference of function declaration in 2/*** var abc = function () {} * can only be used after function declaration * // add (); function add (x, y) {alert (x + y )} // add (1, 2); // add2 (12, 3) var add2 = function (x, y) {alert (x + y)} add2 (12, 3 )})() [javascript]/*** callback function * after calling a function, it will call a function */(function () {// receives the callback function. Function add (x, y, fn) {this. x = x | 1; this. y = y | 1; if (fn) {fn (this. x + this. y) ;}} add (1, 2, function (v) {if (v> 0) {alert ("re> 0 ")} else {alert ("re <= 0") }}) () [javascript]/*** function parameters */(function () {// 1. random function add (x, y, z) {this. x = x | 0; this. y = y | 0; this. z = z | 0; alert (this. x + this. y + this. z)} // add (, 5) // add () // disadvantage: It is impossible for advanced languages such as java to have the features of precise function rewriting. // tips: if your class is a tool class, there is no parameter you receive Preferably an object/*** conf = {gridName: "", gridCode: "", gridSize: ""} */function gridUtil (conf) {alert (conf ["gridName"] + "" + conf ["gridSize"]);} gridUtil ({gridName: "YUNFENGCHENG", gridSize: 10 }); // pass the value or the address var I = 100; var s = "one"; function add3 (I, s) {I ++; s ++ = "--"; // alert (I);} // add3 (I, s); // alert (I); // 100 or 101 // alert (s ); // "one" or one --/*** proof: the basic variable is to pass the value * The parameter passing method of the custom pair is to pass the "Address" * // The object var o = {name: "YUN FENGCHENG "} function change (o) {o [" name "] =" USPCAT. COM "} change (o); alert (o. name)}) () [javascript]/*** function recursion */(function () {// common programming question 1 ~ 100 use recursive algorithms to add (start, end) {var num = 0; num = num + start; if (start <end) {num = num + add (start + 1, end) ;}return num ;}alert (add (1,100 ));})() [javascript]/*** function usage tips */(function () {// proxy function --> use a program to determine the returned new function (which is a production function) // simulate database var person = {"jim": "m", "lili": "w"} var test = function (name) {if (person [name] = "m") {/*** internal medicine, surgery */return function (nk, wk) {alert (nk + "" + wk)} else if (person [name] = "w") {/*** internal medicine, surgery, gynecology */return function (nk, wk, fk) {alert (nk + "" + wk + "" + fk) }}test ("jim ") ("OK", "OK") test ("lili") ("OK", "OK", "no ")})() the next powerful function eval [javascript] (function () {// eval parses a string into a method and calls var str = "var show = function () {alert (100)} () "; // eval (str) // The database returns a string (which looks like a javaScrpit array) var a =" [] "; var array = eval (a); for (var I = 0; I <array. length; I ++) {alert (array [I])}) ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.