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

顺德网站建设价位销售推广的方法都有哪些

顺德网站建设价位,销售推广的方法都有哪些,凡科自助建站系统,大型网站建立箭头函数的缺点 题目 什么时候不能使用箭头函数? 箭头函数的缺点 没有 arguments const fn1 () > {console.log(this, arguments) // 报错,arguments is not defined } fn1(100, 200)无法通过 call apply bind 等改变 this const fn1 () >…

箭头函数的缺点

题目

什么时候不能使用箭头函数?

箭头函数的缺点

没有 arguments

const fn1 = () => {console.log('this', arguments) // 报错,arguments is not defined
}
fn1(100, 200)

无法通过 call apply bind 等改变 this

const fn1 = () => {console.log('this', this) // window
}
fn1.call({ x: 100 })

简写的函数会变得难以阅读

const multiply = (a, b) => b === undefined ? b => a * b : a * b

不适用箭头函数的场景

对象方法

const obj = {name: '双越',getName: () => {return this.name}
}
console.log( obj.getName() )

扩展对象原型(包括构造函数的原型)

const obj = {name: '火龙'
}
obj.__proto__.getName = () => {return this.name
}
console.log( obj.getName() )

构造函数

const Foo = (name, age) => {this.name = namethis.age = age
}
const f = new Foo('火龙', 20) // 报错 Foo is not a constructor

动态上下文中的回调函数

const btn1 = document.getElementById('btn1')
btn1.addEventListener('click', () => {  // console.log(this === window)this.innerHTML = 'clicked'
})

Vue 生命周期和方法

{data() { return { name: '火龙' } },methods: {getName: () => {// 报错 Cannot read properties of undefined (reading 'name')return this.name},// getName() {//     return this.name // 正常// }},mounted: () => {// 报错 Cannot read properties of undefined (reading 'name')console.log('msg', this.name)},// mounted() {//     console.log('msg', this.name) // 正常// }
}

【注意】class 中使用箭头函数则没问题

class Foo {constructor(name, age) {this.name = namethis.age = age}getName = () => {return this.name}
}
const f = new Foo('张三', 20)
console.log('getName', f.getName())

所以,在 React 中可以使用箭头函数

export default class HelloWorld extends React.Component {constructor(props) {super(props)this.state = {name: '双越'}}render() {return <p onClick={this.printName}>hello world</p>}printName = () => {console.log(this.state.name)}
}

答案

箭头函数的缺点

  • arguments 参数
  • 无法改变 this

不适用的场景

  • 对象方法
  • 对象原型
  • 构造函数
  • 动态上下文
  • Vue 生命周期和方法

划重点

  • Vue 组件是一个对象,而 React 组件是一个 class (如果不考虑 Composition API 和 Hooks)

你写出来的代码让所有人都能看懂那才是高级的!受教了!程序员这个职业还是脚踏实地,少出bug,少装逼!

http://www.hkea.cn/news/918685/

相关文章:

  • 帮人做传销网站违法吗seo网站排名助手
  • 如何做优品快报下的子网站营销型网站建设目标
  • 用织梦做网站调用乱码营业推广是什么意思
  • 做走私网站北京口碑最好的it培训机构
  • 网站建设OA系统开发it培训机构哪家好
  • 网站运维可以做哪些域名查询网站入口
  • 网站开发的基本语言外贸平台自建站
  • 女生自己做网站营销方法有哪些
  • 怎么自己做网站吓别人金融网站推广圳seo公司
  • 彩票网站的客服有做吗海淀seo搜索优化多少钱
  • 河源哪有做网站网页模板设计
  • 手机网站可以做英文版本吗近三天时政热点
  • 怎么做网站游戏网络优化排名培训
  • ic外贸网站建设黑帽seo技巧
  • 实业有限公司网站怎么做百度一下了你就知道官网
  • 企业电子商务网站推广平台有哪些渠道
  • 本地用织梦做网站百度的网站网址
  • 基础展示营销型型网站新闻发稿平台有哪些
  • 做游戏赚钱的网站最新新闻热点事件2022
  • 商务网站建设哪家好推广代理公司
  • 自己做网站是否要买云主机西安百度提升优化
  • 成都注册公司哪个区好分析网站推广和优化的原因
  • 模板建站杭州seo泽成
  • 济南网站建设公司川芎网络怎么注册自己的网址
  • linux下安装wordpress关键词优化排名查询
  • wordpress手机网站怎么做中央电视台一套广告价目表
  • 百家号如何给网站做推广推广方案是什么
  • 西安三网合一网站建设产品线上推广方案
  • 2023年免费b站入口百度网站优化
  • 响应式网站建设有利于seo网站发布与推广方案