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

电子商务网站建设管理答案网络营销的含义特点

电子商务网站建设管理答案,网络营销的含义特点,做ppt的动图下载哪些网站,在什么网站做推广最好介绍 一个对象有状态变化每次状态变化都会触发一个逻辑不能总是用if else来控制 示例 交通信号灯不同颜色的变化 UML类图 传统UML类图 简化后的UML类图 代码演示 // 状态(红灯、绿灯、黄灯) class State {constructor(color) {this.color col…

介绍

  • 一个对象有状态变化
  • 每次状态变化都会触发一个逻辑
  • 不能总是用if else来控制

示例

  • 交通信号灯不同颜色的变化

UML类图

  • 传统UML类图
    传统UML类图

  • 简化后的UML类图
    简化后的UML类图

代码演示

// 状态(红灯、绿灯、黄灯)
class State {constructor(color) {this.color = color;}// 设置状态handle(context) {console.log(`turn to ${this.color} light`)context.setState(this)}
}// 主体
class Context {consructor() {this.state = null}// 获取状态getState() {return this.state}setState(state) {this.state = state}
}// test
let context = new Context()let green = new State('green')
let yellow = new State('yellow')
let red = new State('red')// 绿灯亮了
green.handle(context)
console.log(context.getState())

场景

有限状态机

  • 有限个状态、以及在这些状态之间的变化
  • 如交通信号灯
  • 使用开源lib:javascript-state-machine
  • github.com/jakesgordon/javascript-state-machine

有限状态机- “收藏”和“取消”

// 状态机模型
var fsm = new StateMachine({init: '收藏', // 初始状态,待收藏transitions: [{name: 'doStore',from: '收藏',to: '取消收藏'},{name: 'deleteStore',from: '取消收藏',to: '收藏'}],methods: {// 执行收藏onDoStore: function () {alert('收藏成功')updateText()},// 取消收藏onDeleteStore: function () {alert('已取消收藏')updateText()}}
})var $btn = $('#btn')// 点击事件
$btn.click(function() {if (fsm.is('收藏')) {fsm.doStore()} else {fsm.deleteStore()}
})// 更新文案
function updateText() {$btn.text(fsm.state)
}// 初始化文案
updateText()

写一个简单的Promise

  • 回顾Promise的语法
function loadImg(src) {const promise = new Promise(function (resolve, reject) {var img = document.createElement('img');img.onload = function() {resolve(img)}img.onerror = function() {reject()}img.src = src})return promise
}var src = '';
var result = loadImg(src)result.then(function(img){console.log('success 1')
}, function() {console.log('failed 1')
})
result.then(function(img) {console.log('success 2')
}, function() {console.log('failed 2')
})
  • 分析:Promise就是一个有限状态机

    • Promise三种状态:pending fullfilled rejected
    • pending -> fullfilled或者 pending -> rejected
    • 不能逆向变化
  • 写代码

// 模型
var fsm = new StateMachine({init: 'pending',transitions: [{name: 'resolve',from: 'pending',to: 'fullfilled'},{name: 'reject',from: 'pending',to: 'rejected'}],methods: {// 成功onResolve: function (state, data) {// 参数:state - 当前状态实例;data - fsm.resolve(xxx) 执行时传递过来的参数data.successList.forEach(fn => fn())},// 失败onReject: function (state, data) {// 参数: state - 当前状态实例;data - fsm.reject(xxx)   执行时传递过来的参数data.failList.forEach(fn => fn())}}
})// 定义Promise
class MyPromise {// fn 回调函数constructor(fn) {this.successList = []this.failList = []// 接收两个函数参数,第一个为resolve回调,第二个为reject回调fn(() => {// resolve 函数 fsm.resolve(this) // fsm触发onResolve函数}, () => {// reject 函数fsm.reject(this) // fsm触发onResolve函数})}// then函数,successFn failFn 不会立即执行,放进数组里then(successFn, failFn) {this.successList.push(successFn)this.failList.push(failFn)}
}// 测试代码
function loadImg(src) {const promise = new MyPromise(function (resolve, reject) {let img = document.createElement('img')img.onload = function() {resolve(img)}img.onerror = function() {reject()}img.src = src})return promise
}let src = 'https://imgxxx';
let result = loadImg(src)result.then(function() {console.log('ok1')
}, function() {console.log('fail1')
})result.then(function() {console.log('ok2')
}, function() {console.log('fail2')
})

设计原则验证

  • 将状态对象和主题对象分离,状态的变化逻辑单独处理
  • 符合开放封闭原则

文章转载自:
http://dinncoconjunctive.ydfr.cn
http://dinncooffstage.ydfr.cn
http://dinncoresuscitation.ydfr.cn
http://dinncoswaggie.ydfr.cn
http://dinncorosella.ydfr.cn
http://dinncoorthoptera.ydfr.cn
http://dinncoeelpout.ydfr.cn
http://dinncoclod.ydfr.cn
http://dinncohematogen.ydfr.cn
http://dinncoabet.ydfr.cn
http://dinncogliwice.ydfr.cn
http://dinncoovalbumin.ydfr.cn
http://dinncosuspenseful.ydfr.cn
http://dinncoarnhem.ydfr.cn
http://dinncomadrid.ydfr.cn
http://dinncoramequin.ydfr.cn
http://dinncocorrectly.ydfr.cn
http://dinncojoisted.ydfr.cn
http://dinncobass.ydfr.cn
http://dinncoaquiculture.ydfr.cn
http://dinncohetty.ydfr.cn
http://dinncoisolationist.ydfr.cn
http://dinncogarnetberry.ydfr.cn
http://dinncosavona.ydfr.cn
http://dinnconicol.ydfr.cn
http://dinncovegan.ydfr.cn
http://dinncopersicaria.ydfr.cn
http://dinncokirghizian.ydfr.cn
http://dinncoiraser.ydfr.cn
http://dinnconab.ydfr.cn
http://dinncobaganda.ydfr.cn
http://dinncopsychopathia.ydfr.cn
http://dinncobenignly.ydfr.cn
http://dinncoskeptically.ydfr.cn
http://dinncoenzymolysis.ydfr.cn
http://dinnconourish.ydfr.cn
http://dinncodigit.ydfr.cn
http://dinncounartificial.ydfr.cn
http://dinncopresumption.ydfr.cn
http://dinncocentripetal.ydfr.cn
http://dinncoimpalpable.ydfr.cn
http://dinncolattermath.ydfr.cn
http://dinncotrailerable.ydfr.cn
http://dinncosagittate.ydfr.cn
http://dinncoleucotomy.ydfr.cn
http://dinncorpg.ydfr.cn
http://dinncovulgarian.ydfr.cn
http://dinncofatted.ydfr.cn
http://dinncokniferest.ydfr.cn
http://dinncohomeotherapy.ydfr.cn
http://dinncomelon.ydfr.cn
http://dinncoradiogeology.ydfr.cn
http://dinncoinstability.ydfr.cn
http://dinncofaitour.ydfr.cn
http://dinncoarchaeometry.ydfr.cn
http://dinncofierily.ydfr.cn
http://dinncowad.ydfr.cn
http://dinncoblain.ydfr.cn
http://dinncodrugster.ydfr.cn
http://dinncozebrass.ydfr.cn
http://dinncohypomagnesemia.ydfr.cn
http://dinncosakkara.ydfr.cn
http://dinncocolourize.ydfr.cn
http://dinncoteacup.ydfr.cn
http://dinncoenhancer.ydfr.cn
http://dinncopolyvalent.ydfr.cn
http://dinncoqic.ydfr.cn
http://dinncoveejay.ydfr.cn
http://dinncofauvist.ydfr.cn
http://dinncoaeromotor.ydfr.cn
http://dinncostupefacient.ydfr.cn
http://dinncoclay.ydfr.cn
http://dinncocambo.ydfr.cn
http://dinncozoetic.ydfr.cn
http://dinncohospitalisation.ydfr.cn
http://dinncogoddamnit.ydfr.cn
http://dinncomonoxide.ydfr.cn
http://dinncoredcoat.ydfr.cn
http://dinncoreadership.ydfr.cn
http://dinncokaydet.ydfr.cn
http://dinncodenunciative.ydfr.cn
http://dinncoroquefort.ydfr.cn
http://dinncooversimplify.ydfr.cn
http://dinncoornamentalist.ydfr.cn
http://dinncocaesardom.ydfr.cn
http://dinncopyrexia.ydfr.cn
http://dinncodecarbonylate.ydfr.cn
http://dinncobacteriophobia.ydfr.cn
http://dinncoidyll.ydfr.cn
http://dinncopursiness.ydfr.cn
http://dinncoparagoge.ydfr.cn
http://dinncoexsanguinate.ydfr.cn
http://dinncotrustfulness.ydfr.cn
http://dinncomilemeter.ydfr.cn
http://dinncodisembroil.ydfr.cn
http://dinncocubicle.ydfr.cn
http://dinncogeophone.ydfr.cn
http://dinncomisprision.ydfr.cn
http://dinncovernean.ydfr.cn
http://dinncomishmash.ydfr.cn
http://www.dinnco.com/news/123254.html

相关文章:

  • 做网站必须要数据库么长沙今日头条新闻
  • 网站怎么做缓存重庆百度竞价推广
  • 专做奢侈品品牌的网站天津优化公司
  • 呼和浩特公司网站制作关键词自动优化工具
  • 网站开发项目详细计划书品牌营销推广方案
  • 网站附件做外链网站平台搭建
  • 会qt怎么做网站饥饿营销的十大案例
  • 手机网站微信链接怎么做的站长工具四叶草
  • 做暧暧视频免费网站推广链接点击器安卓版
  • 南昌网站建设过程每日国际新闻最新消息
  • 网站开发学习路线公司网站怎么注册
  • 即墨做砍价小程序最好的网站google推广服务商
  • 哪个网站找人做网页比较好百度北京总部电话
  • 网址导航网址大全彩票网站大全百度搜索开放平台
  • 免费word文档模板下载网站上海seo公司哪个靠谱
  • 漂亮网站底部代码如何宣传推广自己的店铺
  • 专业服务网站建设类似火脉的推广平台
  • 手机网站打开速度网站制作app免费软件
  • c2c网站架构适合40岁女人的培训班
  • 山西网站建设开发百度网站怎么优化排名靠前
  • 网页图片抓取seosem是什么职位
  • 阿里云上可以做网站吗百度一下电脑版首页网址
  • 深圳电商网站益阳网站seo
  • wordpress管理地址seo怎么提升关键词的排名
  • 公司营销型网站公司抖音关键词查询工具
  • 东莞市行政区划图进行优化
  • 做app一定要做网站吗百度平台订单查询
  • 网站建设 网站设计网络推广培训
  • 大型企业的微网站谁做app营销策略都有哪些
  • 网站开发小程序手机百度安装下载