[Javascript] Funciton Expression
JavaScript expression
2023-09-14 08:59:21 时间
//This will load the code into the memory no matter //you call it or not function diffOfSquares(a,b){ return a*a -b*b; } //This code will only load into memory when you call it. var diff = function diffOfSquares(a,b){ return a*a-b*b; }; diff(9,5); //Call diff function instead of diffOfSquares //So why we still need diffOfSquares, since we don't call it /** Anonymour Function */ var diff = function(a,b){ return a*a-b*b; }; //You can use console.log(diff); It will print out the //function instead of the value, so you can check what //this function refer to. /********************************************/ var greeting = function(){ alert("Thank for fucking!"); }; closeTerminal(greeting); function closeTerminal(message){ ... message(); .... } //We pass greeting as param to the closeTerminal function /* function closeTerminal(greeting){ ... greeting(); ... } */ //The out put would be //"Thank for fucking!" /*********************************************/ //According to difference cases, the greeting message //may be different. //For example, newCustomer & oldCustomer, we want to //take them differently. var greeting; ... //Some code to sets new newCustomer to ture of false if(newCustomer){ greeting = function(){ alert("Thanks for funcking!"); }; }else{ greeting = function(){ alert("Welcome to be fucked!"); }; } closeTerminal(greeting); //if newCustomer is true, --> Thanks for funcking! //if newCustomer is false, --> Welcome to be fucked!
相关文章
- javascript html转换成markdown,如何使用Turndown使用JavaScript将HTML转换为Markdown[通俗易懂]
- JavaScript案例:倒计时
- 关于Java&JavaScript中(伪)Stream式API对比的一些笔记
- javascript生成/解析dom的CDATA类型的字段的代码
- Javascript常用运算符(Operators)-javascript基础教程
- Javascript更新JavaScript数组的uniq方法
- JavaScript验证浏览器是否支持javascript的方法小结
- javascript最常用的10个自定义函数[推荐]
- javascript正则表达式(一)
- JavaScript的document对象和window对象详解
- JavaScript高级程序设计阅读笔记(十四)js继承机制的实现
- 一个JavaScript变量声明的知识点
- 如何学习Javascript入门指导
- JavaScript中的变量定义与储存介绍