Coder Social home page Coder Social logo

choicejs's Introduction

choicejs

Build Status Build version

install

你可以通过yarn或者npm安装choicejs

$ npm install choicejs
$ yarn add choicejs

require or import

const choicejs = require('choicejs').Choice;

import { Choice } from 'choicejs'

usage

add(description: string, condition: boolean, callback: any, extend?: string)

该方法是用来增加你的选择的,有四个参数,description代表你对当前选择的描述,该项千万不要重复,否则后面增加的选择会覆盖之前的,第二个选项就是判断条件,第三个代指满足判断条件时的回调方法,最后一个参数为可选参数,代指继承于某项描述,就好比嵌套的if...else嵌套于某个条件一样。

一个栗子:

const judgeTree = new Choice();

const logAisBiggerThan1() {
  console.log('a > 1')
};

const logAisSmallerThan9() {
  console.log('a < 9');
}

const a = 3;

judgeTree
  .add('biggerThan1', a > 1, logAisBiggerThan1)
  .add('smallerThan9', a < 9, logAisSmallerThan9, 'biggerThan1')

use()

简单暴力的方法,add用来定义,而use就是用来执行。如果没有use,那么定义好的决策树就像是一个定义好的函数,没有()它就毫无卵用~

栗子:

judgeTree.use();

// 注意,judgeTree 是支持链式调用的,所以放心大胆地将 use() 接在 add() 之后使用吧~

destroy()

简单的销毁方法,使用完之后可以选择清空当前实例中的所有信息,通常作为最后一步使用,在此就不举例啦~

choicejs's People

Contributors

jeasonnow avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

ll790226724

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.