vue导出js中的函数

In JavaScript, we have got four major things to do:-

在JavaScript中,我们要做四件事:

  1. To Store values.存储值。
  2. To Store a series of steps.存储一系列步骤。
  3. To make decisions.做出决定。
  4. To Repeat the steps. (loops)

    要重复这些步骤。 (循环)

In this article, we will mainly focus on “storing a series of steps”. And to do that we need to learn about function because, in js, function helps us to store a series of steps and execute those steps/codes whenever required by calling that function.

在本文中,我们将主要集中于“存储一系列步骤”。 为此,我们需要学习函数,因为在js中,函数可帮助我们存储一系列步骤,并在需要时通过调用该函数执行这些步骤/代码。

Now coming to the syntax of the function, we have got several ways to define a function but the most basic way is to “declare a function” which is termed as function declaration.

现在来看函数的语法,我们有几种定义函数的方法,但是最基本的方法是“声明一个函数”,称为函数声明

The snippet above shows the most basic way to declare a function.

上面的代码段显示了声明函数的最基本方法。

So, this is the first step in writing a function and the next step is to “call the function” and to do that we need to just write the name of the function i.e “add” and put the parenthesis (()) after that.

因此,这是编写函数的第一步,而下一步是“调用函数” ,为此,我们只需要写函数名即“ add ”,然后在其后加上括号( () ) 。

With that, we have seen how to declare a function and then “give a call to that”. One more important thing to note here is that we can call this function anywhere we want, like whenever we call this function we will get the code executed present between the curly braces.

至此,我们已经看到了如何声明一个函数,然后“对其进行调用”。 这里要注意的另一件重要事情是,我们可以在任何需要的地方调用此函数,就像每当调用此函数时,我们都会在花括号之间得到执行的代码。

功能类型 (Types of functions)

  1. function expression

    功能表达

Above we have seen the most basic type of function which is function declaration. Now we will see the second type i.e. function expression.

上面我们看到了最基本的函数类型,即函数声明。 现在我们将看到第二种类型,即函数表达式

So, to define a variable using let, var or const we need these keywords, then the name of the variable and then the assignment operator and then the value. Like this:-

因此,要使用letvarconst定义变量,我们需要这些关键字,然后是变量的名称,然后是赋值运算符,然后是值。 像这样:-

let user = "sushant";

Now, to the right of assignment operator(=) we can only have string, number, boolean, null, undefined and object and any value other than that will be treated as an invalid value.

现在,在赋值运算符(=)的右边,我们只能有字符串,数字,布尔值,null,未定义和对象,除此以外的任何值都将被视为无效值。

So, in JS, functions are treated as an object. So, we can define it to the right of assignment operator like this:-

因此,在JS中,函数被视为对象。 因此,我们可以在赋值运算符的右侧定义它,如下所示:-

let user = function user() {    return "riya";}user();

So, this is known as a function expression.

因此,这称为函数表达式

2. Anonymous function expression

2.匿名函数表达式

An anonymous function expression is almost similar to function expression, the only difference is that, in this, we omit the name of the function, like this:-

匿名函数表达式几乎类似于函数表达式,唯一的区别是,在此,我们省略了函数名称,如下所示:

let user = function () {  //name 'user' is omitted    return "riya";}user();

3. Arrow function

3.箭头功能

For an arrow function, we can say that it’s a kind of a short form of anonymous function expression. In writing arrow function, we omit the word function from it and just use parenthesis and after parenthesis add the symbol “=>”, like this:-

对于箭头函数,可以说这是匿名函数表达式的一种简短形式 在编写箭头函数时,我们从中省略单词function ,仅使用括号,并在括号后添加符号“ => ”,如下所示:-

let user = () => {    return "riya";}user();

Now, if there is only one line in curly braces then we can omit these curly braces and the keyword “return” too:-

现在,如果花括号中只有一行,那么我们可以省略这些花括号,而关键字“ return ”也可以省略:

let user = () => "riya";user();

带参数的功能 (Function with arguments)

Now that we have discussed the most basic part of functions and almost all types of functions, we will learn about function with arguments.

既然我们已经讨论了函数的最基本部分以及几乎所有类型的函数,我们将学习带参数的函数

Sometimes what happens is that we need to get different “return” value but the steps should be the same. For example:- we need to do the same operation, say multiplication, but with different operands, in that case we need to write the function again and again. So, here we use functions with arguments, Like this: -

有时发生的事情是我们需要获得不同的“返回”值,但步骤应该相同。 例如:-我们需要执行相同的运算(例如乘法),但使用不同的操作数,在这种情况下,我们需要一次又一次地编写函数。 所以,在这里我们使用功能与参数,像这样: -

function mul(a, b) {    return a * b;};console.log(mul(20, 30));console.log(mul(10, 15));

Hence, in this case, we don’t need to write the code, again and again, we just need to change the arguments & we will get the result.

因此,在这种情况下,我们不需要一遍又一遍地编写代码,只需更改参数即可得到结果。

So, that was all about functions with arguments.

因此,这全都与带有参数的函数有关。

Tbasics of functions are left, that is, about “return” keyword and “function with default parameter”. We may discuss these in future.

剩下的函数基本知识,即“ return ”关键字和“带有默认参数的函数”。 我们将来可能会讨论这些。

Thank you.

谢谢。

翻译自: https://medium.com/@sushantsareen456/functions-in-js-a2beb4a59198

vue导出js中的函数


http://www.taodudu.cc/news/show-2702719.html

相关文章:

  • java queue toarray_Java PriorityBlockingQueue toArray()用法及代码示例
  • HDR显示器在 windows/PC 下正确的使用方式
  • Docker Swarm 练习:投票 App
  • python爬虫笔记(3)
  • 试用Riya-带有人脸识别功能的在线照片服务
  • 特征函数(characteristic function)
  • CHARACTERISTIC DEFINITION
  • Euler characteristic
  • Flutter for ble 之set_notification_error, could not locate CCCD descriptor for characteristic分析(原生角度)
  • BLE协议栈入门二(添加service和characteristic)
  • 最后采用加权求和的方式得到样本的_论文阅读笔记《Principal characteristic networks for few-shot...
  • 通俗理解ROC曲线(Receiver Operating Characteristic Curve)
  • 论文阅读笔记《Principal characteristic networks for few-shot learning》
  • Receiver Operating Characteristic(ROC)
  • 土壤水分特征参数估计(soil water characteristic)
  • ESP32开发路程蓝牙篇——BLE(GATT),修改设备名称,添加characteristic,发送数据,接收数据
  • 第二章 Silicon labs EFR32 MG21 验证蓝牙的私有Characteristic的读/写
  • BLE service, characteristic以及CCCD概念 9
  • Python - matplotlib - ROC曲线(Receiver Operating Characteristic curve)
  • 低功耗蓝牙ATT/GATT/Profile/Service/Characteristic解读
  • nRF52832 GATT 自定义Service/Characteristic
  • 【蓝牙开发】低功耗蓝牙ATT/GATT/Profile/Service/Characteristic规格解读
  • ESP32-C3 学习测试 蓝牙 篇(五、添加 characteristic)
  • BLE service, characteristic
  • BLE 怎样添加 Characteristic
  • 6.2 Characteristic Values
  • BLE中的Service(服务)和characteristic(特征值)
  • 银行卡识别技术-移动支付新宠儿
  • Jenkins构建从github上克隆时,报Host key verification failed.
  • 仿照中国银行页面进行编写,主要涉及到float,定位

vue导出js中的函数_js中的函数相关推荐

  1. js 浅拷贝直接赋值_JS中实现浅拷贝和深拷贝的代码详解

    (一)JS中基本类型和引用类型 JavaScript的变量中包含两种类型的值:基本类型值 和 引用类型值,在内存中的表现形式在于:前者是存储在栈中的一些简单的数据段,后者则是保存在堆内存中的一个对象. ...

  2. js中every用法_JS中every()和some()的用法

    every()与some()方法都是JS中数组的迭代方法. every()是对数组中每一项运行给定函数,如果该函数对每一项返回true,则返回true. some()是对数组中每一项运行给定函数,如果 ...

  3. js延时函数_js自执行函数分享

    自执行函数是从哪里了解到的呢,从学习延时器settimeout(fn,time)的时候 测试一个for循环里面加一个延时器,想要每隔一秒输出一次i for(var i=0;i<6;i++){ s ...

  4. js 将内部函数变成全局函数_js中三种作用域详解(全局,函数,块级)

    1.全局变量:声明在函数外部的变量(所有没有var直接赋值的变量都属于全局变量) 2.局部变量:声明在函数内部的变量(所有没有var直接赋值的变量都属于全局变量) JS中变量申明分显式申明和隐式申明. ...

  5. js 实现2的n次方计算函数_JS中数据结构与算法---排序算法

    排序算法的介绍 排序也称排序算法 (Sort Algorithm),排序是将 一组数据 , 依指定的顺序 进行 排列的过程 . 排序的分类 内部排序 : 指将需要处理的所有数据都加载 到 内部存储器( ...

  6. java定义js函数_JS中可以先使用函数,然后再定义.

    首先要说明的,下面这种方式是对的,虽然不知道为什么,很奇怪为什么可以先使用,再定义,希望有了解的人可以给个说法. hello('www.openj.cn'); function hello(name) ...

  7. jq js json 转字符串_JS中JSON对象和String之间的互转及处理技巧

    json:JavaScript 对象表示法(javascript Object Notation),其实JSON就是一个javaScript的对象(Object)而已. 如有不清楚JSON,可以去w3 ...

  8. js 上下箭头滚动_JS中的this完全讲解,再也不会被this搞晕了

    关于This对象 js 中的this 是一个比较难理解的对象:所以也经常作为面试的考点,考察应聘者的js 基础能力:其实this的指向也就那么几种情况,接下来我们一一看一下: 函数中的this取何值是 ...

  9. js 多个定时器_JS中的同步/异步编程

    1. 进程(process)/线程(thread) 进程process: 电脑端安装很多的应用软件,每当运行一个应用程序,相当于开辟一个进程(而对于浏览器来说,每新建一个页卡访问一个页面,都是新开辟一 ...

  10. js 浅拷贝直接赋值_JS中的赋值、浅拷贝与深拷贝

    作者:奚杰 拷贝是写代码中经常使用的方法.浅拷贝与深拷贝是指拷贝的两种情况.本文将深入探究JS的赋值.浅拷贝与深拷贝. 数据类型 在探究深拷贝与浅拷贝之前,我们先梳理一下JS的数据类型.在JavaSc ...

最新文章

  1. Puppet--用户自动化管理
  2. 详解异构计算FPGA基础知识
  3. jQuery Zoom 图片聚焦或者点击放大A plugin to enlarge images on touch, click, or mouseover
  4. python 微信公众号-回调模式验证url
  5. Go语言中协程的概念和基本使用
  6. thinkphp 中英文语言包
  7. 怎么把倒数日放到桌面上,华为电脑便签怎么在桌面上显示倒计时
  8. 网络编程(第一天)--TCP网络编程
  9. C++17之std::apply与std::make_from_tuple
  10. oracle如何获取xml节点,oracle解析xml,带命令空间的节点获取
  11. 什么是CDN?CDN的技术原理是什么?
  12. 计算机毕业设计Java东理咨询交流论坛(源码+系统+mysql数据库+lw文档)
  13. USB-serial驱动分析(usb转串口)
  14. 关卡理论(1)第一节:概念
  15. 网路设备的端口镜像技术
  16. 判断字符串是否存在于文件中
  17. python-OpenCV图像处理常用函数汇总(三)
  18. 来,我教你怎么优雅删除数据
  19. mysql获取连续登陆大于等于3天的用户id
  20. ANT DESIGN VUE upload 上传excel (使用upliad组件,上传excel到页面表格)

热门文章

  1. 聚焦Java性能优化 打造亿级流量秒杀系统【学习笔记】01_电商秒杀商品回顾
  2. IOS学习笔记-加速度传感器(重力感应)-UIAccelerometer
  3. 【leetcode】出界的路径数----迭代问题与计算思维
  4. 10计算机网络需要密码是多少钱,Win10宽带连接不用每次都要输入密码的办法
  5. 工业控制计算机固态硬盘,工业级SSD接口全解析,懂了你才会选对工业级SSD
  6. 微信文件夹的dat文件怎么打开_微信dat后缀的文件怎么打开
  7. 微信公众号第三方平台授权流程
  8. App自动化测试怎么做?实战分享App自动化测试全流程
  9. Tkinter模块GUI界面化编程实战(七)——人机对战五子棋(含超详解及完整源码、完整程序免费下载链接)
  10. Mac Xshell 下载 (FinallShell)