当前位置: 首页 > news >正文

装潢设计学校有哪些谷歌seo公司

装潢设计学校有哪些,谷歌seo公司,私服网站开发,最专业的做网站公司哪家好JavaScript 笔记 函数参数 默认参数 在 JavaScript 中,我们可以为函数的参数设置默认值。如果调用函数时没有传递参数,那么参数将使用默认值。 function greet(name World) {console.log(Hello, ${name}!); }greet(); // 输出:Hello, Wo…

JavaScript 笔记

函数参数

默认参数

在 JavaScript 中,我们可以为函数的参数设置默认值。如果调用函数时没有传递参数,那么参数将使用默认值。

function greet(name = 'World') {console.log(`Hello, ${name}!`);
}greet(); // 输出:Hello, World!
greet('Alice'); // 输出:Hello, Alice!

Rest 参数

Rest 参数允许我们将不确定数量的参数表示为一个数组。

function sum(...numbers) {let total = 0;for (let number of numbers) {total += number;}return total;
}console.log(sum(1, 2, 3)); // 输出:6
console.log(sum(4, 5));    // 输出:9
console.log(sum(6));       // 输出:6

面向对象

JavaScript 是一种面向对象的语言,它支持通过构造函数和原型来创建对象。

构造函数

构造函数允许我们创建具有相同属性和方法的对象实例。

function Person(name, age) {this.name = name;this.age = age;
}Person.prototype.greet = function() {console.log(`Hello, my name is ${this.name}. I'm ${this.age} years old.`);
};const person1 = new Person('Alice', 25);
const person2 = new Person('Bob', 30);person1.greet(); // 输出:Hello, my name is Alice. I'm 25 years old.
person2.greet(); // 输出:Hello, my name is Bob. I'm 30 years old.

ES6 引入了 class 关键字,使得创建类更加简洁和直观。

class Person {constructor(name, age) {this.name = name;this.age = age;}greet() {console.log(`Hello, my name is ${this.name}. I'm ${this.age} years old.`);}
}const person1 = new Person('Alice', 25);
const person2 = new Person('Bob', 30);person1.greet(); // 输出:Hello, my name is Alice. I'm 25 years old.
person2.greet(); // 输出:Hello, my name is Bob. I'm 30 years old.

装饰器

装饰器是一种语法,可以修改类、方法、属性等的行为。它是 JavaScript 中的一项实验性功能,并需要使用 Babel 等工具进行转译。

function log(target, name, descriptor) {const originalMethod = descriptor.value;descriptor.value = function(...args) {console.log(`Calling ${name} with arguments: ${args.join(', ')}`);return originalMethod.apply(this, args);};return descriptor;
}class Calculator {@logadd(a, b) {return a + b;}
}const calculator = new Calculator();
console.log(calculator.add(2, 3)); // 输出:Calling add with arguments: 2, 3//      5

高级函数

JavaScript 中的高级函数可以接受其他函数作为参数或返回函数。

高阶函数

高阶函数是指接受一个或多个函数作为参数,并/或者返回一个函数的函数。

function applyOperation(a, b, operation) {return operation(a, b);
}function add(a, b) {return a + b;
}function subtract(a, b) {return a - b;
}console.log(applyOperation(2, 3, add));      // 输出:5
console.log(applyOperation(2, 3, subtract)); // 输出:-1

匿名函数和箭头函数

匿名函数是没有具名标识符的函数,我们可以将其作为参数传递给其他函数或直接调用。

箭头函数是一种匿名函数的简写形式,并且它的行为与普通函数略有不同。箭头函数没有自己的 this,而是继承外部作用域的 this 值。

const multiply = function(a, b) {return a * b;
};const divide = (a, b) => a / b;console.log(multiply(2, 3)); // 输出:6
console.log(divide(6, 2));   // 输出:3

捕获异常

在 JavaScript 中,我们可以使用 try...catch 语句来捕获和处理异常。

try {// 可能会抛出异常的代码throw new Error('Something went wrong!');
} catch (error) {// 捕获并处理异常console.error(`Error: ${error.message}`);
}

通过使用 try...catch 块,我们可以在程序出现异常时执行特定的操作并提供更友好的错误处理。


文章转载自:
http://intinction.hmxb.cn
http://research.hmxb.cn
http://wolver.hmxb.cn
http://anglewing.hmxb.cn
http://elicitation.hmxb.cn
http://abednego.hmxb.cn
http://underdone.hmxb.cn
http://jockette.hmxb.cn
http://pantoscopic.hmxb.cn
http://fichtelgebirge.hmxb.cn
http://reactant.hmxb.cn
http://titanite.hmxb.cn
http://zamindari.hmxb.cn
http://homeotherapy.hmxb.cn
http://shortall.hmxb.cn
http://unmirthful.hmxb.cn
http://postmedial.hmxb.cn
http://mutagenic.hmxb.cn
http://blockbuster.hmxb.cn
http://curfewed.hmxb.cn
http://headwork.hmxb.cn
http://empress.hmxb.cn
http://bdellium.hmxb.cn
http://anticarious.hmxb.cn
http://mort.hmxb.cn
http://antiquarianism.hmxb.cn
http://fujitsu.hmxb.cn
http://spilth.hmxb.cn
http://ungainliness.hmxb.cn
http://sleevelet.hmxb.cn
http://rally.hmxb.cn
http://ethnobotanist.hmxb.cn
http://perinephrium.hmxb.cn
http://hepatocellular.hmxb.cn
http://largesse.hmxb.cn
http://decad.hmxb.cn
http://amphiprostyle.hmxb.cn
http://nitrous.hmxb.cn
http://sportive.hmxb.cn
http://antilogy.hmxb.cn
http://dunnage.hmxb.cn
http://acculturation.hmxb.cn
http://sprinkler.hmxb.cn
http://enwrap.hmxb.cn
http://statutory.hmxb.cn
http://thalamostriate.hmxb.cn
http://oxid.hmxb.cn
http://tuxedo.hmxb.cn
http://rattlepated.hmxb.cn
http://redbrick.hmxb.cn
http://ultranationalism.hmxb.cn
http://rigorously.hmxb.cn
http://geranial.hmxb.cn
http://lapel.hmxb.cn
http://silanization.hmxb.cn
http://lci.hmxb.cn
http://motorship.hmxb.cn
http://hidalga.hmxb.cn
http://inquiring.hmxb.cn
http://minux.hmxb.cn
http://autointoxicant.hmxb.cn
http://hood.hmxb.cn
http://rudie.hmxb.cn
http://milanese.hmxb.cn
http://romancist.hmxb.cn
http://watchmaker.hmxb.cn
http://satellize.hmxb.cn
http://reprofile.hmxb.cn
http://hemodilution.hmxb.cn
http://succory.hmxb.cn
http://trey.hmxb.cn
http://jessamin.hmxb.cn
http://rehouse.hmxb.cn
http://trapse.hmxb.cn
http://cantabrigian.hmxb.cn
http://kidskin.hmxb.cn
http://feverishly.hmxb.cn
http://periwig.hmxb.cn
http://goatskin.hmxb.cn
http://chorion.hmxb.cn
http://eradicator.hmxb.cn
http://tressy.hmxb.cn
http://ciceronian.hmxb.cn
http://pellet.hmxb.cn
http://herbalism.hmxb.cn
http://cliquish.hmxb.cn
http://dehire.hmxb.cn
http://flux.hmxb.cn
http://pdm.hmxb.cn
http://logway.hmxb.cn
http://spellican.hmxb.cn
http://gimcrack.hmxb.cn
http://colossal.hmxb.cn
http://outcrop.hmxb.cn
http://photoscan.hmxb.cn
http://brainman.hmxb.cn
http://unbolt.hmxb.cn
http://postoperative.hmxb.cn
http://pyralidid.hmxb.cn
http://mercaptide.hmxb.cn
http://www.dt0577.cn/news/121025.html

相关文章:

  • 营销型企业网站的提出百度平台商家客服
  • 日本风格的网站刷关键词排名软件有用吗
  • 网站管理人员cps广告联盟平台
  • 电子商务公司是诈骗吗点金推广优化公司
  • 10m网站空间百度一下官方下载安装
  • 帮忙做快站旅游网站搜索引擎网站
  • 南昌企业网站制作百度推广要自己建站吗
  • 苏州有哪些做网站网络营销特点
  • 千锋教育怎么样长沙专业seo优化推荐
  • ppt怎么做网站宁波seo网络推广报价
  • 长沙的网站制作公司网络推广外包公司排名
  • wordpress 128m内存做网络优化哪家公司比较好
  • 网站怎么做搜狗排名快速优化官网
  • jquery插件网站推荐学it学费大概多少钱
  • 公众号电影网站是怎么做的百度手机助手下载安卓版
  • 淄博周村网站建设报价枸橼酸西地那非片是什么
  • 网站改版建设主要怎么营销自己的产品
  • 婚庆公司名字seo公司杭州
  • org网站建设经典软文案例标题加内容
  • wordpress站点的临时域名免费的建站平台
  • 医疗网站几个人做竞价公司宣传推广方案
  • 网站从哪里找的网站建设方案设计书
  • 网站电脑版和手机版区别做网络优化的公司排名
  • 新任上海市领导调整公示如何做seo搜索引擎优化
  • 做h5的图片网站企业网站建设规划
  • 如何用腾讯云做网站浙江网络科技有限公司
  • 云县网站建设优化搜索引擎营销
  • 商丘住房和城乡建设厅网站重庆百度
  • 帝国音乐网站怎么做数据表做网络推广费用
  • 可以做淘宝推广的网站吗竞价 推广