jojomany / JS-VariableListener

Simple function to listen variables changing.Get changing variables' info,able to make own functions.Support Mobile-devices,able to log in a div witch is dragabled./监听JS中的变量变化,获取指定变量变化信息,并支持自定义方法。支持移动设备,可以将自定义的log信息显示在一个可以拖动的DIV中。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VariableListener WIKI


Include/引用方式: ---- ``` <script src="your direct/varListener.min.js"></script> ``` Include before the js file witch need to listen variable/在需要监听变量的js文件前引用

Usage/使用方法:

Grammar/语法

varListen('variables',callBack(response),pollingTime,showLog)

Arguments/参数介绍

var variable01;

varListen(
'variable01', //The variable need to be listened.Variables should be involved in `quotes`.This argument is required.
              //需要被监听的变量,变量需要用`引号`包围,必填参数。
             
function(res){ //Callback.Respose got 3 property: res.varLog ; res.varName ; res.varValue.This argument is required.
               //回调,返回值有3个方法:res.varLog ; res.varName ; res.varValue。必填参数。
              
    console.log(res.varLog) //res.varLog return a String: variableName = variableValue;
                            //res.varLog 返回一个字符串:变量名 = 变量数值;
                           
    console.log(res.varName) //res.varName return a String, the name of changed variable.
                             //res.varName 返回字符串:发生变化的变量名。
                            
    console.log(res.varValue) //res.Value return the value of changed variable.
                              //res.Value返回的是发生变化的变量值。
},
500, //This listen function based on polling.So this argument can set polling time.Optional, default: `500`ms;
     //本控件的功能基于对变量的轮询,可以通过该参数设置轮询时间。可选项,默认为`500`毫秒。
    
15 //If this number argument been setted, a div whitch log variables'infos you setted before will be create to the body,and the div's fontSize will be set to this argument.
     //And the Div can be draged to anywhere.Suitable for mobiles. Optional.
     //如果此参数被设置,将会向body添加一个用来显示你所设定的变量信息的div,这个div是可以拖动的,而你设定的参数值将决定div的字体大小。
     //适用于移动设备的测试。可选项。
)

This function can be repeated used to listen multiple variables.You can also set multiple variables in the first arguments in one function, split variables with ,.

这个方法可以反复使用。也可以在同一个方法中的第一个参数中设置多个变量的监听。用,分隔变量。

Example/示例

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>varListener</title>
    <script src="varListener.js"></script>
</head>
<body>

<script >
    var variable01=1,
            variable02=[1,2,3],
            variable03="Hi~";

    varListen('variable01,variable02',function(res){
        console.log(res.varLog);
//        alert(res.varName+"Changed")
        console.log(res.varValue)
    })

    varListen('variable03,variable01',function(res){
        if(res.varName=='variable03') {  //way to select variable from variables you've setted
                                         //可以通过此方法从你设置的变量中选择你要添加功能的变量
            eval(res.varName + "+='Thanks~'") //way to handle with variable in response.equal to variable03+='Thanks~'
                                              //可通过此方法从回调参数中抽取变量并使用。此行代码等同于variable03+='Thanks~'
        }
    },1000,20)

</script>

<input type="button" value="ChangeV01" onclick="variable01+=1">
<input type="button" value="ChangeV02" onclick="variable02.push(0)">
<input type="button" value="ChangeV03" onclick="variable03+='!'">

</body>
</html>

About

Simple function to listen variables changing.Get changing variables' info,able to make own functions.Support Mobile-devices,able to log in a div witch is dragabled./监听JS中的变量变化,获取指定变量变化信息,并支持自定义方法。支持移动设备,可以将自定义的log信息显示在一个可以拖动的DIV中。


Languages

Language:JavaScript 100.0%