官术网_书友最值得收藏!

  • Ext JS 3.0 Cookbook
  • Jorge Ramon
  • 146字
  • 2021-04-01 13:43:45

Effortless range checking for numbers

Now, you'll see how to use Ext JS in order to guarantee that a number falls within a certain range.

How to do it...

The following steps illustrate how to perform range checking on numeric values:

  1. Create your sample numbers:
    var number1 = 30;
    var number2 = 75;
    
  2. Check whether your numbers are within a range:
    var constrained = number1.constrain(25, 50);
    // constrained is 30 because number1 is
    // within the specified range
    constrained = number2.constrain(25, 50);
    // constrained is 50 because number2 is
    // greater than the max. value in the range
    

How it works...

Ext.Number is a one-function extension of the JavaScript Number object. The only function of Ext.Number is constrain(min, max), which simply uses methods of the Math JavaScript object to accomplish the range checks on the given number.

constrain: function(min, max) {
return Math.min(Math.max(this, min), max);
}
主站蜘蛛池模板: 久治县| 阿拉善右旗| 历史| 屏山县| 柏乡县| 呼玛县| 仙游县| 洱源县| 格尔木市| 依安县| 山丹县| 会泽县| 叙永县| 鄄城县| 莱阳市| 广灵县| 祥云县| 万荣县| 灌阳县| 和林格尔县| 浪卡子县| 霞浦县| 仪征市| 九龙县| 宁晋县| 永安市| 丹巴县| 息烽县| 隆昌县| 英吉沙县| 汉川市| 鄯善县| 马鞍山市| 衡阳县| 大理市| 四川省| 阿合奇县| 昌宁县| 南川市| 建湖县| 阳谷县|