Skip to content

angelise7/WeChatGame

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

如果觉得代码库太大,可以参考我以前写的表达式分析算法的文章 https://blog.csdn.net/jiexiaopei_2004/article/details/41546673

include Binding.js

support type : number,bool,string,var

support operate : + - * / % ! << >> >>> > < >= <= == === !== != & ~ ^ | && || ?: ()

Examples

  1. simple expr
console.log(binding.eval("(1 + 2) * 4 / 2")); //console 6
  1. expr with var
var v0 = 3;
console.log(binding.eval("$0 * 4",[v0])); //console 12
  1. expr with var and function
var v0 = 3;
var v1 = 6;
console.log(binding.eval("Math.sqrt($0 * 3 * $1 * 6)",[v0,v1])); //console 18
  1. expr with var and self-define function
var v0 = 9;
var addFunction = function(a,b) {
    return a + b;
}
console.log(binding.eval("add(Math.sqrt($0), 2)",[v0],{add:addFunction})); //console 5
  1. 3 op expr
console.log(binding.eval("3 > 2 ? true : false")); //console true

when this project receive 100 star,i will support define var in the script, and so on.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published