JS中创建函数的几种方式

  1. 使用 "函数声明" 创建函数

       语法:*         function 函数名([形参1,形参2...形参N]){*             语句...*         }
         */function fun2(){console.log("这是我的第二个函数~~~");alert("哈哈哈哈哈");document.write("~~~~(>_<)~~~~");}
  1. 使用 "函数表达式" 来创建一个函数

    var 函数名  = function([形参1,形参2...形参N]){*      语句....*  }
    (可分两种):// 1.命名函数表达式var testA=function abc(){console.log(aaa);}// 2.匿名函数表达式  --最常用简称函数表达式var testB=function(){console.log(bbb);}
  1. 使用 "构造函数"

      * 构造函数的执行流程:*     1.立刻创建一个新的对象*     2.将新建的对象设置为函数中this,在构造函数中可以使用this来引用新建的对象*     3.逐行执行函数中的代码*     4.将新建的对象作为返回值返回* * 使用同一个构造函数创建的对象,我们称为一类对象,也将一个构造函数称为一个类。*     我们将通过一个构造函数创建的对象,称为是该类的实例
         function Person(name , age , gender){this.name = name;this.age = age;this.gender = gender;this.sayName = function(){alert(this.name);};}function Dog(){}var per = new Person("黎",18,"女");

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/276107.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网页设计简约_简约网页设计的主要功能

网页设计简约重点 (Top highlight)Minimalism is synonymous with simplicity. Not quite. As the name suggests, minimalism is definitely not about opulent design. But the assumption that minimalism is design-less and plain is also wrong. Minimalism is simple ye…

Expo 2010 Japan Pavilion

^_^转载于:https://www.cnblogs.com/mmmhhhlll/archive/2010/04/16/1713680.html

深度对比学习Vue和React两大框架

作为国内应用最广的两个框架&#xff0c;Vue 和 React 是前端必须掌握的内容&#xff0c;也是面试的重点。但大多数读者都只擅长其中一个框架&#xff0c;当面试涉及到另一个框架的内容时&#xff0c;就答不好了。比如虚拟dom&#xff0c;两个框架中都有应用&#xff0c;面试官…

java rwd_面向任务的设计-不仅限于Mobile First和RWD

java rwdWe already know that majority of solutions should start with a design for smartphones, we know that all websites should be responsive. Now, it’s time to think about holistic solutions with specific tasks adapted to all kind of devices.我们已经知道…

HOJ 1015 Nearly prime numbers

代码 //Nearly prime number is an integer positive number for which it is possible //to find such primes P1 and P2 that given number is equal to P1*P2.#include <stdio.h>#include <stdlib.h>#include <math.h>//decide n whither is a nearly pri…

「前端工程化」该怎么理解?

大家好&#xff0c;我是若川。今天分享一篇「前端工程化」的好文。非广告&#xff0c;请放心阅读。可点击下方卡片关注我&#xff0c;或者查看系列文章。今天发文比较晚&#xff0c;以往都是定时早上7:30发文&#xff0c;也不知道是不是有点早。一.什么是前端工程&#xff1f;一…

figma下载_Figma和ProtoPie中的原型制作,比较

figma下载第1部分 (Part 1) Prototyping has never had such a high profile with a whole host of tools that now give you varying ability to realize your designs beyond their static UI and into a working usable thing. It’s fair to say that prototyping within t…

「前端组件化」该怎么理解?

大家好&#xff0c;我是若川。今天分享一篇关于「前端组件化」的好文。欢迎点击下方卡片关注我。以下是正文~这里我们一起来学习前端组件化的知识&#xff0c;而组件化在前端架构里面是最重要的一个部分。讲到前端架构&#xff0c;其实前端架构中最热门的就有两个话题&#xff…

大屏设计的视觉统一_视觉设计中的统一

大屏设计的视觉统一视觉设计的统一性是什么&#xff1f; (What is unity in visual design?) The concept of unity in visual design means a group of elements working together to create a greater whole. It means, as the clich goes: A whole that is greater than th…

跟着官方文档能学懂React Hooks就怪了

大家好&#xff0c;我是若川。今天分享一篇关于「React Hooks」的好文。欢迎点击下方卡片关注我。以下是正文~回想下你入门Hooks的过程&#xff0c;是不是经历过&#xff1a;类比ClassComponent的生命周期&#xff0c;学习Hooks的执行时机慢慢熟练以后&#xff0c;发现Hooks的执…

origin图上显示数据标签_Origin(Pro):寒假都结束了,这个图还是不会画?【数据绘图】...

寒假前给大家分享了一个图&#xff0c;大家要的教程来了。【数据绘图】好图分享&#xff1a;寒假&#xff1f;不存在的&#xff01;​mp.weixin.qq.com绘图思路&#xff1a;左侧起止时间&#xff1a;散点图&#xff0c;交换XY坐标轴&#xff1b;中间的连线为Drop Lines&#xf…

可以激发设计灵感的音乐_建立灵感库以激发您的创造力

可以激发设计灵感的音乐I often find a lot of inspiration from work I see while scrolling social media. Saving art or images that inspire you allows you to build a library of resources to draw from whenever you’re working on a project.在滚动社交媒体时&#…

若川知乎问答:做前端感觉很吃力怎么办?

前些日&#xff0c;我发了一篇推文《做前端感到越来越吃力了&#xff01;怎么办&#xff1f;》&#xff0c;虽然是推广&#xff0c;但阅读量却很高&#xff0c;推广标题我们大概率不能改&#xff0c;感觉骗了大家&#xff0c;掉粉挺多人。写稿的人可能就是看到了知乎这个问答。…

d3 制作条形图_停止制作常见的坏条形图的5个简单技巧

d3 制作条形图Bar charts were probably the first type of chart you were ever introduced to in first grade. Their simplicity makes them a standard in visualizing data, but it is its accessibility that leads visualizers to often be careless with bar charts.乙…

SVN之使用原则

以下是我起草的部门SVN规范里原则的一部分。文件提交时要求必须提交注释&#xff0c;注明相关修改信息&#xff0c;例如bug号、任务描述等。具体内容可采用约定或者设置的形式。你所提交的改变将体现给其他开发者&#xff0c;要明白提交的后果&#xff0c;提交之前要慎重。代码…

图解 React-router 源码

大家好&#xff0c;我是若川。欢迎加我微信 ruochuan12今天分享一篇react-router源码文章&#xff0c;深入理解路由的本质。微信预计阅读只需8分钟。点击下方卡片关注我&#xff0c;或者查看源码系列文章。阅读源码小 tips&#xff1a;从整体到细节&#xff0c;刚开始不要太拘泥…

android 辅助功能_辅助功能简介

android 辅助功能Accessibility may be more than a moral imperative to ensure products are inclusive of more people who already experience barriers in daily life — it has a very practical outcome, benefiting everyone including the person with the disability…

推荐几个前端大佬,真的厉害!

新的一年&#xff0c;推荐几个还在坚持输出的高质量前端公众号&#xff0c;你想要的&#xff1a;React/Vue/Node/工程化/面试经验等&#xff0c; 这里都有。不多说&#xff0c;直接看介绍。???? 程序员成长指北考拉&#xff0c;一个有趣且乐于分享的妹子&#xff0c;专注 N…

RawCode-本身就是实验性的8位类型

What if a type is created solely from the bit-representation of characters?如果仅根据字符的位表示形式创建类型怎么办&#xff1f; This question was the basis of creating this experimental type. The type no longer uses familiar characters. ‘A’ looks like …

2d访问冲突_Light | 基于环形分隔微镜阵列的高速随机访问轴向聚焦系统

撰稿 | OSANJU 刘 扬01导读近日&#xff0c;来自美国加州大学伯克利分校的Rikky Muller教授团队&#xff0c;在国际顶尖学术期刊《Light: Science & Applications》发表了题为“A micromirror array with annular partitioning for high-speed random-access axial focus…