Class: Setter

Setter

Abstract class to be extended to gain input validation for a class' setter methods.

<abstract> new Setter()

Fake constructor. This abstract class is supposed to be extended using Inheritance light extension.
Example
define(["Inheritance","Setter"],function(Inheritance,Setter) {
  
  var MyClass = function() {
    this.exampleProperty = 1;
    //do stuff
  }
  
  MyClass.prototype = {
    setExampleProperty: function(newVal) {
      this.exampleProperty = this.checkPositiveNumber(newVal,false,false);
    },
  
    //declare more stuff
  };
  
  Inheritance(MyClass,Setter,true);
  return MyClass;
});

Method Summary

checkBool
Checks the given value to be a boolean.
checkPositiveNumber
Checks the given value to be a valid number.

Method Detail

<protected> checkBool(newVal, notStrictFalse) → {Boolean}

Checks the given value to be a boolean. The check is performed with the strict equal operactor (i.e.: ===)
If specified, empty strings, nulls, NaN, 0s, negative numbers and undefineds are also admitted values and are interpreted as false.
Parameters:
Name Type Description
newVal the value to be verified.
notStrictFalse if true anything that would not-strictly equal (==) false is considered as a valid false.
Throws:
if the input value is not a valid boolean.
Type
IllegalArgumentException
Returns:
Type
Boolean

<protected> checkPositiveNumber(newVal, canBeZero, canBeDecimal) → {Number}

Checks the given value to be a valid number. The input value is first explicitly converted into a Number (e.g. null would become 0) then is checked to be a valid number and finally it is verified against the input configurations.
Parameters:
Name Type Description
newVal Number | String | Object the value to be verified.
canBeZero Boolean specifies if the given value can be 0 or not.
canBeDecimal Boolean specifies if the given value can be a decimal number or not.
Throws:
if the input value is not a number or does not respect one of the given constraint.
Type
IllegalArgumentException
Returns:
The explicitly converted Number is returned.
Type
Number