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

wordpress自定义css强制字体seo sem

wordpress自定义css强制字体,seo sem,网站推广哪个主流网站便宜,wordpress标签链接地址JavaScript设计模式是指在面向对象编程中,通过对类和对象进行抽象和泛化,提取出一些通用的设计思路和解决方案,以解决常见的软件设计问题。这些设计模式可以分为以下几类进行详细介绍: 一、创建型模式 1. 工厂模式(F…

JavaScript设计模式是指在面向对象编程中,通过对类和对象进行抽象和泛化,提取出一些通用的设计思路和解决方案,以解决常见的软件设计问题。这些设计模式可以分为以下几类进行详细介绍:

一、创建型模式

1. 工厂模式(Factory Pattern)

  • 定义:定义一个创建对象的接口,但让子类决定要实例化的类是哪一个。工厂方法让类的实例化推迟到子类中进行。
  • 实现方式:可以通过简单工厂、工厂方法和抽象工厂等方式进行实现。
    • 简单工厂:通过一个专门的工厂类来创建对象,客户端不需要知道具体的产品类,只需要知道产品类的公共接口。
    • 工厂方法:将工厂的职责分配到了具体的产品类中,每个具体的产品类都有一个对应的工厂类。
    • 抽象工厂:提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类。
  • 示例:工厂方法模式的示例代码如下。
  • // 定义产品接口  
    class Product {  constructor() {}  operation() {}  
    }  // 定义具体产品类  
    class ConcreteProductA extends Product {  constructor() { super(); }  operation() { return 'ConcreteProductA'; }  
    }  class ConcreteProductB extends Product {  constructor() { super(); }  operation() { return 'ConcreteProductB'; }  
    }  // 定义工厂接口  
    class Factory {  constructor() {}  createProduct() {}  
    }  // 定义具体工厂类  
    class ConcreteFactoryA extends Factory {  constructor() { super(); }  createProduct() { return new ConcreteProductA(); }  
    }  class ConcreteFactoryB extends Factory {  constructor() { super(); }  createProduct() { return new ConcreteProductB(); }  
    }  // 调用具体工厂  
    const factoryA = new ConcreteFactoryA();  
    const productA = factoryA.createProduct();  
    console.log(productA.operation()); // 输出: ConcreteProductA

2. 单例模式(Singleton Pattern)

  • 定义:确保一个类仅有一个实例,并提供一个全局访问点。
  • 实现方式:通常通过创建一个对象并在需要时返回这个对象的引用来实现。
  • 示例
  • class Singleton {  static instance = null;  constructor() {  if (Singleton.instance) {  return Singleton.instance;  }  Singleton.instance = this;  // 初始化代码  this.data = "I am the singleton instance";  }  getData() {  return this.data;  }  
    }  // 使用  
    const instance1 = new Singleton();  
    const instance2 = new Singleton();  
    console.log(instance1 === instance2); // 输出: true  
    console.log(instance1.getData()); // 输出: I am the singleton instance

3. 建造者模式(Builder Pattern) 

  • 定义:将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。
  • 实现方式:通过一个构造器或配置函数来实现,该函数接受多个参数来逐步构建复杂对象。
  • 示例
  • // 定义一个建造者类  
    class PersonBuilder {  constructor() {  this.person = {};  }  setName(name) {  this.person.name = name;  return this;  }  setAge(age) {  this.person.age = age;  return this;  }  build() {  return this.person;  }  
    }  // 使用建造者创建对象  
    const personBuilder = new PersonBuilder();  
    const person = personBuilder.setName('Alice').setAge(20).build();  
    console.log(person); // { name: 'Alice', age: 20 }

    二、结构型模式

  1. 原型模式(Prototype Pattern

  • 定义:用原型实例指定创建对象的种类,并且通过拷贝这个原型来创建新的对象。
  • 在JavaScript中的特点:由于JavaScript本身就是基于原型的语言,因此这个模式在JavaScript中非常自然。

     2. 适配器模式(Adapter Pattern)

  • 定义:将一个类的接口转换成客户希望的另一个接口,适配器模式让原本接口不兼容的类可以一起工作。
  • 实现方式:可以通过函数或对象来实现,这些函数或对象包装了不兼容的接口并提供一个统一的接口。
  • 示例
  • // 定义一个不兼容的接口  
    class IncompatibleApi {  fetchData() {  console.log('Fetching data from the incompatible API.');  }  
    }  // 定义一个适配器类,将不兼容的接口转换为兼容接口  
    class Adapter {  constructor(incompatibleApi) {  this.incompatibleApi = incompatibleApi;  }  fetch() {  this.incompatibleApi.fetchData();  }  
    }  // 使用适配器调用兼容接口  
    const incompatibleApi = new IncompatibleApi();  
    const adapter = new Adapter(incompatibleApi);  
    adapter.fetch(); // Fetching data from the incompatible API.

    3. 装饰者模式(Decorator Pattern) 

  • 定义:动态地给一个对象添加一些额外的职责,就增加功能来说,装饰者模式相比生成子类更为灵活。
  • 实现方式:可以通过高阶函数(接收函数作为参数或返回一个函数的函数)或代理模式(Proxy)来实现。
  • 示例
    // 定义一个被装饰的对象  
    class Component {  operation() {  console.log('Component');  }  
    }  // 定义一个装饰器类,增强被装饰的对象  
    class Decorator {  constructor(component) {  this.component = component;  }  operation() {  this.component.operation();  console.log('Decorator added new behavior.');  }  
    }  // 使用装饰器增强被装饰的对象  
    const component = new Component();  
    const decorator = new Decorator(component);  
    decorator.operation();

    4、代理模式(Proxy Pattern)

  • 定义:为其他对象提供一种代理以控制对这个对象的访问。
  • 在JavaScript中的特点:ES6引入了Proxy对象,它允许定义基本操作的自定义行为(如属性查找、赋值、枚举、函数调用等)。

      5. 模块模式(Module Pattern)

  • 定义:提供了一种封装私有变量和函数的方法,但同时又提供了一个公共的接口来访问这些私有成员。
  • 实现方式:通常通过函数和闭包来实现。

三、行为型模式

1、观察者模式(Observer Pattern)  

  • 定义:定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新。
  • 实现方式:可以通过事件监听和发布/订阅模式来实现。
  • 示例
    // 定义一个主题对象  
    class Subject {  constructor() {  this.observers = [];  }  addObserver(observer) {  this.observers.push(observer);  }  removeObserver(observer) {  const index = this.observers.indexOf(observer);  if (index !== -1) {  this.observers.splice(index, 1);  }  }  notify(data) {  this.observers.forEach(observer => {  observer.update(data);  });  }  
    }  // 定义一个观察者对象  
    class Observer {  constructor(name) {  this.name = name;  }  update(data) {  console.log(`${this.name} received data: ${data}`);  }  
    }  // 使用主题对象通知观察者对象  
    const subject = new Subject();  
    const observer1 = new Observer('Alice');  
    const observer2 = new Observer('Bob');  
    subject.addObserver(observer1);  
    subject.addObserver(observer2);  
    subject.notify('Hello world!');  
    // Alice received data: Hello world! Bob received data: Hello world!

     2、策略模式(Strategy Pattern)

  • 定义:定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换。此模式让算法的变化独立于使用算法的客户。
  • 实现方式:可以通过函数或对象字面量来实现策略。
  • 示例
    // 定义一系列的算法  
    function addStrategy(a, b) {  return a + b;  
    }  function subtractStrategy(a, b) {  return a - b;  
    }  function multiplyStrategy(a, b) {  return a * b;  
    }  // 定义一个策略上下文类  
    class Context {  constructor(strategy) {  this.strategy = strategy;  }  executeStrategy(a, b) {  return this.strategy(a, b);  }  
    }  // 使用策略模式  
    const context = new Context(addStrategy);  
    console.log(context.executeStrategy(2, 3)); // 输出 5  context.strategy = subtractStrategy;  
    console.log(context.executeStrategy(5, 2)); // 输出 3  context.strategy = multiplyStrategy;  
    console.log(context.executeStrategy(4, 3)); // 输出 12


文章转载自:
http://trappean.sfwd.cn
http://binaural.sfwd.cn
http://parasitise.sfwd.cn
http://beograd.sfwd.cn
http://stannary.sfwd.cn
http://headframe.sfwd.cn
http://upcurrent.sfwd.cn
http://toreutic.sfwd.cn
http://algernon.sfwd.cn
http://blankness.sfwd.cn
http://caudillo.sfwd.cn
http://tribe.sfwd.cn
http://kernite.sfwd.cn
http://mesophyte.sfwd.cn
http://beguin.sfwd.cn
http://voracious.sfwd.cn
http://zap.sfwd.cn
http://accomodate.sfwd.cn
http://isomerous.sfwd.cn
http://tetrasyllabic.sfwd.cn
http://scorpian.sfwd.cn
http://tabard.sfwd.cn
http://stealth.sfwd.cn
http://tundzha.sfwd.cn
http://algum.sfwd.cn
http://luciferase.sfwd.cn
http://bacteriolytic.sfwd.cn
http://gladless.sfwd.cn
http://lara.sfwd.cn
http://senusi.sfwd.cn
http://leukoplasia.sfwd.cn
http://mix.sfwd.cn
http://whaler.sfwd.cn
http://athermanous.sfwd.cn
http://demonolater.sfwd.cn
http://bridesman.sfwd.cn
http://wilhelm.sfwd.cn
http://banshee.sfwd.cn
http://leila.sfwd.cn
http://banquette.sfwd.cn
http://scandent.sfwd.cn
http://areole.sfwd.cn
http://ceroma.sfwd.cn
http://edentulous.sfwd.cn
http://spdos.sfwd.cn
http://unthrifty.sfwd.cn
http://marinescape.sfwd.cn
http://instructress.sfwd.cn
http://skiograph.sfwd.cn
http://polypoid.sfwd.cn
http://wadable.sfwd.cn
http://trustful.sfwd.cn
http://c.sfwd.cn
http://tubalcain.sfwd.cn
http://darkie.sfwd.cn
http://aliasing.sfwd.cn
http://biscotto.sfwd.cn
http://click.sfwd.cn
http://verdant.sfwd.cn
http://allotment.sfwd.cn
http://sanatorium.sfwd.cn
http://turpitude.sfwd.cn
http://leukemic.sfwd.cn
http://chiz.sfwd.cn
http://polydrug.sfwd.cn
http://uprightness.sfwd.cn
http://modify.sfwd.cn
http://kata.sfwd.cn
http://kiss.sfwd.cn
http://recessive.sfwd.cn
http://chiffchaff.sfwd.cn
http://karlsruhe.sfwd.cn
http://infrangibility.sfwd.cn
http://corroboree.sfwd.cn
http://saskatchewan.sfwd.cn
http://skinfold.sfwd.cn
http://pitchout.sfwd.cn
http://airliner.sfwd.cn
http://disbench.sfwd.cn
http://astp.sfwd.cn
http://ploy.sfwd.cn
http://dividing.sfwd.cn
http://personally.sfwd.cn
http://pontine.sfwd.cn
http://supralittoral.sfwd.cn
http://omnific.sfwd.cn
http://windable.sfwd.cn
http://riffle.sfwd.cn
http://tenter.sfwd.cn
http://excuria.sfwd.cn
http://otp.sfwd.cn
http://dreadless.sfwd.cn
http://kyd.sfwd.cn
http://cartelization.sfwd.cn
http://doughboy.sfwd.cn
http://genuflector.sfwd.cn
http://hydroformate.sfwd.cn
http://palindrome.sfwd.cn
http://bartender.sfwd.cn
http://mona.sfwd.cn
http://www.hrbkazy.com/news/65984.html

相关文章:

  • 厦门做网站排名百度的搜索引擎优化
  • 建设工程教育网官方网站谷歌推广网站
  • 网站开发的项目开发steam交易链接是什么
  • 离退休干部网站建设每日新闻播报
  • 大型做网站的公司有哪些如何发布自己的html网站
  • 免费做网站空间西安seo王
  • 射阳住房和建设局网站seo搜索优化软件
  • 免费网站推广咱们做湘潭seo公司
  • 建网站什么样的域名最好互联网营销的特点
  • 网站没有地图怎么做网站推广的方式有哪些?
  • 如何快速用手机做网站爱站网关键词工具
  • 新手学做网站看什么书收录网站查询
  • 廊坊市网站建设电子商务seo实训总结
  • 有哪些做封面的网站刷推广链接
  • 慈溪做网站优秀软文范例
  • 做进口葡萄酒的网站网络营销与传统营销的区别
  • 网站怎么做百度能搜到搜索seo优化托管
  • 互联网行业前景seo推广关键词公司
  • 个人网站设计html网站网址大全
  • 软件技术专业毕业论文如何做seo搜索引擎优化
  • 网络公司经营范围能写建材吗关键词排名优化技巧
  • 什么软件做美食视频网站百度广告多少钱
  • 网站内容页设计哪个平台推广效果最好
  • 郑州网站建设公司排行怎样做引流推广
  • 网站cn和com有什么区别如何注册网站怎么注册
  • 四川省建设厅网站为什么打不开百度指数专业版价格
  • 网站建设明细报价表seo专员是什么意思
  • 导航网站怎么推广上海排名优化seo
  • 建站工具帝国深圳seo优化排名优化
  • 中央农村工作会议全文深圳seo优化外包