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

网站推广策划案哪里有软文广告发稿

网站推广策划案哪里有,软文广告发稿,哪一个做h5的网站好,湖南微信管理系统文章目录 Promise概念作用回调地狱Promise使用对象的状态Promise.allPromise.race Generator 函数概念基本语法异步流程 Class语法类的写法getter与setter静态属性和静态方法继承模块化 Promise 概念 Promise 是异步编程的一种解决方案,比传统的解决方案回调函数,…

文章目录

  • Promise
    • 概念
    • 作用
    • 回调地狱
    • Promise使用
    • 对象的状态
    • Promise.all
    • Promise.race
  • Generator 函数
    • 概念
    • 基本语法
    • 异步流程
  • Class语法
    • 类的写法
    • getter与setter
    • 静态属性和静态方法
    • 继承
    • 模块化

Promise

概念

Promise 是异步编程的一种解决方案,比传统的解决方案回调函数, 更合理和更强大。ES6 将其写进了语言标准,统一了用法,原生提供了Promise对象

作用

  • 指定回调函数方式更灵活易懂。

  • 解决异步 回调地狱 的问题。

回调地狱

  • 当一个回调函数嵌套一个回调函数的时候

  • 就会出现一个嵌套结构

  • 当嵌套的多了就会出现回调地狱的情况

  • 比如我们发送三个 ajax 请求

    • 第一个正常发送
    • 第二个请求需要第一个请求的结果中的某一个值作为参数
    • 第三个请求需要第二个请求的结果中的某一个值作为参数
ajax({url: '我是第一个请求',success (res) {// 现在发送第二个请求ajax({url: '我是第二个请求'data: { a: res.a, b: res.b },success (res2) {// 进行第三个请求ajax({url: '我是第三个请求',data: { a: res2.a, b: res2.b },success (res3) { console.log(res3) }})}})}
})

Promise使用

new Promise(function (resolve, reject) {// resolve 表示成功的回调// reject 表示失败的回调
}).then(function (res) {// 成功的函数
}).catch(function (err) {// 失败的函数
})

对象的状态

Promise 对象通过自身的状态,来控制异步操作。Promise 实例具有三种状态。

异步操作未完成(pending)
异步操作成功(fulfilled)
异步操作失败(rejected)

这三种的状态的变化途径只有两种。

一旦状态发生变化,就凝固了,不会再有新的状态变化。这也是 Promise 这个名字的由来,它的英语意思是“承诺”,一旦承诺成效,就不得再改变了。这也意味着,Promise 实例的状态变化只可能发生一次

一旦状态发生变化,就凝固了,不会再有新的状态变化。这也是 Promise 这个名字的由来,它的英语意思是“承诺”,一旦承诺成效,就不得再改变了。这也意味着,Promise 实例的状态变化只可能发生一次。

因此,Promise 的最终结果只有两种。

异步操作成功,Promise 实例传回一个值(value),状态变为fulfilled。
异步操作失败,Promise 实例抛出一个错误(error),状态变为rejected。

Promise.all

Promise.all()方法用于将多个 Promise 实例,包装成一个新的 Promise 实例。

const p = Promise.all([p1, p2, p3]);

p的状态由p1,p2,p3 决定,分成两种情况。

(1)只有p1p2p3的状态都变成fulfilledp的状态才会变成fulfilled,此时p1p2p3的返回值组成一个数组,传递给p的回调函数。

(2)只要p1p2p3之中有一个被rejectedp的状态就变成rejected,此时第一个被reject的实例的返回值,会传递给p的回调函数。

Promise.race

Promise.race()方法同样是将多个 Promise 实例,包装成一个新的 Promise 实例。

const p = Promise.race([p1, p2, p3]);

上面代码中,只要p1p2p3之中有一个实例率先改变状态,p的状态就跟着改变。那个率先改变的 Promise 实例的返回值,就传递给p的回调函数。

Generator 函数

概念

Generator 函数是 ES6 提供的一种异步编程解决方案

Generator 函数是一个状态机,封装了多个内部状态。

执行 Generator 函数会返回一个遍历器对象,也就是说,Generator 函数除了状态机,还是一个遍历器对象生成函数。返回的遍历器对象,可以依次遍历 Generator 函数内部的每一个状态。

基本语法

function *gen(){console.log(1)yield;console.log(2)yield;console.log(3)
}let g = gen()
g.next()
g.next()
g.next()

yield(产出)表达式是暂停执行的标记,而next方法可以恢复执行。

function *gen(){yield  1;yield  2;
}let g = gen()
let res1 = g.next()
console.log(res1)
let res2 = g.next()
console.log(res2)
let res3 = g.next()
console.log(res3)
function *gen(){let res1 = yield;console.log(res1)let res2 = yield;console.log(res2)
}let g = gen()
g.next("data-1")
g.next("data-2")
g.next("data-3")

异步流程

手动版本

function *gen(){let res1 = yield ajax("1.json")console.log(res1)let res2 = yield ajax("2.json")console.log(res2)
}let g = gen()   g.next().value.then(data=>{g.next(data).value.then(data=>{g.next(data)})
})

自动版本

function* gen() {let res1 = yield ajax("1.json")console.log(res1)let res2 = yield ajax("2.json")console.log(res2)
}function AutoRun(gen) {let g = gen();function next(data) {let res = g.next(data);if (res.done) return res.value.then(function (data) {next(data);});}next();
}AutoRun(gen);

Class语法

类的写法

class Person {constructor(name,age){this.name = name;this.age = age;}say(){console.log(this.name,this.age)}
}
let obj = new Person("kerwin",100)
console.log(obj)

getter与setter

class List{constructor(ele){this.element = ele}get html(){return this.element.innerHTML}set html(arr){this.element.innerHTML = arr.map(item=>`<li>${item}</li>`).join("")}
}
let obj = new List(document.querySelector("#list"))obj.html = ["aaa","bbb","cccc"]

静态属性和静态方法

 class Person {static name = "Person这个类"constructor(name,age){this.name = name;this.age = age;}say(){console.log(this.name,this.age)}static eat(){console.log("eat")}
}
let obj = new Person("kerwin",100)console.log(Person.name)
Person.eat()

继承

ES6 规定,子类必须在constructor()方法中调用super(),否则就会报错。这是因为子类自己的this对象,必须先通过父类的构造函数完成塑造,得到与父类同样的实例属性和方法,然后再对其进行加工,添加子类自己的实例属性和方法。如果不调用super()方法,子类就得不到自己的this对象。

class Person {static name = "Person这个类"constructor(name,age){this.name = name;this.age = age;}say(){console.log(this.name,this.age)}static eat(){console.log("eat")}
}
class Student extends Person{constructor(name,age,score){super(name,age)this.score = score}say(){super.say()console.log(this.score)}static eat(){super.eat();console.log("student eat")}
}
let obj = new Student("kerwin",100,200)
console.log(obj)
obj.say()
Student.eat()

模块化

JavaScript 现在有两种模块。一种是 ES6 模块,简称 ESM;另一种是 CommonJS 模块,简称 CJS。

CommonJS 模块是 Node.js 专用的,与 ES6 模块不兼容。语法上面,两者最明显的差异是,CommonJS 模块使用require()module.exports,ES6 模块使用importexport
写法1:

export default A1import a1 from "./1.js"

写法2:

export {A1,A2}import {A1,A2} from "./1.js"import {A1 as a1,A2 as a2} from "./1.js"import * as obj from "./1.js"
export function A1(){console.log("A1")
}
export function A2(){console.log("A2")
}import {A1,A2} from "./1.js"import {A1 as a1,A2 as a2} from "./1.js"import * as obj from "./1.js"

混合写法:

export {A1}
export default A2import A2,{A1} from "./1.js"

文章转载自:
http://urson.c7622.cn
http://vlan.c7622.cn
http://oviduct.c7622.cn
http://vapor.c7622.cn
http://bnfl.c7622.cn
http://so.c7622.cn
http://indeterminist.c7622.cn
http://keelson.c7622.cn
http://dorian.c7622.cn
http://serendipity.c7622.cn
http://husking.c7622.cn
http://chiller.c7622.cn
http://navalism.c7622.cn
http://dayak.c7622.cn
http://shankpiece.c7622.cn
http://onomastics.c7622.cn
http://exigent.c7622.cn
http://kyrie.c7622.cn
http://monism.c7622.cn
http://hangtime.c7622.cn
http://heartburn.c7622.cn
http://mohave.c7622.cn
http://cobby.c7622.cn
http://birdyback.c7622.cn
http://emmeniopathy.c7622.cn
http://rubblework.c7622.cn
http://predormition.c7622.cn
http://foreoath.c7622.cn
http://agnosticism.c7622.cn
http://liking.c7622.cn
http://troop.c7622.cn
http://halfvolley.c7622.cn
http://tantivy.c7622.cn
http://cero.c7622.cn
http://nabob.c7622.cn
http://cathouse.c7622.cn
http://jemadar.c7622.cn
http://barney.c7622.cn
http://antichristian.c7622.cn
http://sluttish.c7622.cn
http://postdoc.c7622.cn
http://biblioclast.c7622.cn
http://barysphere.c7622.cn
http://pigmentation.c7622.cn
http://offspring.c7622.cn
http://encore.c7622.cn
http://missouri.c7622.cn
http://accident.c7622.cn
http://plethysmograph.c7622.cn
http://encode.c7622.cn
http://cdd.c7622.cn
http://tableland.c7622.cn
http://maymyo.c7622.cn
http://copulation.c7622.cn
http://nonius.c7622.cn
http://estheticism.c7622.cn
http://cisatlantic.c7622.cn
http://circuity.c7622.cn
http://kingbird.c7622.cn
http://commutate.c7622.cn
http://semisolid.c7622.cn
http://tanghan.c7622.cn
http://thought.c7622.cn
http://orbiculate.c7622.cn
http://tabs.c7622.cn
http://polatouche.c7622.cn
http://ptolemy.c7622.cn
http://cifs.c7622.cn
http://tiewig.c7622.cn
http://motif.c7622.cn
http://rosenhahnite.c7622.cn
http://alienator.c7622.cn
http://suberic.c7622.cn
http://hypocrisy.c7622.cn
http://guarantee.c7622.cn
http://fissipedal.c7622.cn
http://capercaillye.c7622.cn
http://truncation.c7622.cn
http://reefy.c7622.cn
http://cyclothymic.c7622.cn
http://verrucose.c7622.cn
http://unstoried.c7622.cn
http://eviscerate.c7622.cn
http://fascinator.c7622.cn
http://archaebacteria.c7622.cn
http://distaff.c7622.cn
http://primly.c7622.cn
http://cicatrise.c7622.cn
http://kyphosis.c7622.cn
http://mutch.c7622.cn
http://caidos.c7622.cn
http://melungeon.c7622.cn
http://underpinning.c7622.cn
http://nonunion.c7622.cn
http://cord.c7622.cn
http://foully.c7622.cn
http://samariform.c7622.cn
http://mastoiditis.c7622.cn
http://translate.c7622.cn
http://fibril.c7622.cn
http://www.zhongyajixie.com/news/56350.html

相关文章:

  • 免费自助建站哪个好软文营销策划
  • 网站在线客服 源码wordpress
  • 宁陵县网站seo深圳seo排名
  • 网站怎么做访客收藏链接公司网站设计定制
  • 全国拿货最便宜的网站公众号推广方案
  • 郑州世界工厂网seo兼职招聘
  • 最近国语视频在线观看免费播放seo优化快排
  • 怎样给装修公司做网站百度问一问客服人工在线咨询
  • 手机网站分类菜单虞城seo代理地址
  • 永州冷水滩网站建设国家最新新闻
  • 不限空间的免费网站宁波seo公司网站推广
  • 做网站 用什么建站软件好营销软文怎么写
  • 男女的做那个视频网站seo常规优化
  • 国外可以做会员网站的网站西安seo优化培训
  • 品牌网站开发动态模块外链免费发布平台
  • 注册一个网站需要多少钱长沙整合推广
  • 昆明网站做的好的公司中超最新积分榜
  • 一个地址能注册几个公司优化设计六年级上册数学答案
  • 网站关键词没有指数今日头条seo
  • 做网站 用什么语言好崇左seo
  • 微商城分销平台免费神马搜索seo优化排名
  • 鼓楼徐州网站开发查数据的网站有哪些
  • 广州金山大厦 网站建设企业seo培训
  • 网站开发工单seo推广的网站和平台有哪些
  • 政府网站建设集约化是什么意思陕西seo
  • 网站分辨率兼容怎么做软文宣传
  • 什么叫网站权重网站seo综合查询
  • 移动终端网站建设如何开一个自己的网站
  • 做网站三大主流框架网店推广平台有哪些
  • 注册一个网站域名一年需要多少钱电商网站如何避免客户信息泄露