KEMBAR78
Javascript function | PPTX
 Specifies the number of arguments
expected by the function.
 Syntax
› functionName.length
 console.log( (function () {}).length );
 console.log( (function (a) {}).length );
 console.log( (function (a, b) {}).length );
 function ArgTest(a, b){
 var s = "";
 s += "Expected Arguments: " + ArgTest.length;
 s += "<br />";
 s += "Passed Arguments: " + arguments.length;
 return s;
 }
 Calls a function with a given this value and
arguments provided individually.
 Syntax
› fun.call(thisArg[, arg1[, arg2[, ...]]])
 function diplayInfo(year, month, day){
 return "Name:" + this.name + ";birthday:" + year +
"." + month + "." + day;
 }
 var p = { name: "Jason" };
 diplayInfo.call(p, 1985, 11, 5);
 Calls a function with a given this value
and arguments provided as an array
 Syntax
› fun.apply(thisArg[, argsArray])
 function diplayInfo(year, month, day){
 return "Name:" + this.name + ";birthday:" + year +
 "." + month + "." + day;
 }
 var p = { name: "Jason" };
 console.log(diplayInfo.apply(p, [1985, 11, 5]));
 Specifies the currently executing function
 callee is a property of the arguments object.
 Syntax
› [function.]arguments.callee
 function factorial(n){
 if (n <= 0)
 return 1;
 else
 return n * arguments.callee(n - 1);
 }
 factorial(4);
 Creates a new function that, when
called, has its this keyword set to the
provided value, with a given sequence
of arguments preceding any provided
when the new function is called.
 Syntax
fun.bind(thisArg[, arg1[, arg2[, ...]]])
 var x = 9;
 var module = {
 x: 81,
 getX: function() { return this.x; }
 };
 module.getX(); //Answer: ?
 var getX = module.getX;
 getX(); //Answer: ?
 var boundGetX = getX.bind(module);
 boundGetX(); //Answer: ?
 module.x = 100;
 boundGetX(); //Answer: ?
 var checkNumericRange = function (value) {
 return value >= this.min && value <= this.max;
 }
 var range = { min: 10, max: 20 };
 var boundCheckNumericRange =
checkNumericRange.bind(range);
 var result = boundCheckNumericRange (12);
 Result = ??
 var displayArgs = function (val1, val2, val3, val4) {
 console.log(val1 + " " + val2 + " " + val3 + " " +
val4);
 }
 var emptyObject = {};
 var displayArgs2 =
displayArgs.bind(emptyObject, 12, "a");
 displayArgs2("b", "c"); //Answer: ?
 Javascript MDN
› https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Obj
ects/Function
 Javascript MSDN
› http://teamserver:8080/tfs/DefaultCollection/!Ba
cklog/_boards

Javascript function

  • 2.
     Specifies thenumber of arguments expected by the function.  Syntax › functionName.length
  • 3.
     console.log( (function() {}).length );  console.log( (function (a) {}).length );  console.log( (function (a, b) {}).length );
  • 4.
     function ArgTest(a,b){  var s = "";  s += "Expected Arguments: " + ArgTest.length;  s += "<br />";  s += "Passed Arguments: " + arguments.length;  return s;  }
  • 5.
     Calls afunction with a given this value and arguments provided individually.  Syntax › fun.call(thisArg[, arg1[, arg2[, ...]]])
  • 6.
     function diplayInfo(year,month, day){  return "Name:" + this.name + ";birthday:" + year + "." + month + "." + day;  }  var p = { name: "Jason" };  diplayInfo.call(p, 1985, 11, 5);
  • 7.
     Calls afunction with a given this value and arguments provided as an array  Syntax › fun.apply(thisArg[, argsArray])
  • 8.
     function diplayInfo(year,month, day){  return "Name:" + this.name + ";birthday:" + year +  "." + month + "." + day;  }  var p = { name: "Jason" };  console.log(diplayInfo.apply(p, [1985, 11, 5]));
  • 9.
     Specifies thecurrently executing function  callee is a property of the arguments object.  Syntax › [function.]arguments.callee
  • 10.
     function factorial(n){ if (n <= 0)  return 1;  else  return n * arguments.callee(n - 1);  }  factorial(4);
  • 11.
     Creates anew function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.  Syntax fun.bind(thisArg[, arg1[, arg2[, ...]]])
  • 12.
     var x= 9;  var module = {  x: 81,  getX: function() { return this.x; }  };  module.getX(); //Answer: ?  var getX = module.getX;  getX(); //Answer: ?  var boundGetX = getX.bind(module);  boundGetX(); //Answer: ?  module.x = 100;  boundGetX(); //Answer: ?
  • 13.
     var checkNumericRange= function (value) {  return value >= this.min && value <= this.max;  }  var range = { min: 10, max: 20 };  var boundCheckNumericRange = checkNumericRange.bind(range);  var result = boundCheckNumericRange (12);  Result = ??
  • 14.
     var displayArgs= function (val1, val2, val3, val4) {  console.log(val1 + " " + val2 + " " + val3 + " " + val4);  }  var emptyObject = {};  var displayArgs2 = displayArgs.bind(emptyObject, 12, "a");  displayArgs2("b", "c"); //Answer: ?
  • 15.
     Javascript MDN ›https://developer.mozilla.org/en- US/docs/Web/JavaScript/Reference/Global_Obj ects/Function  Javascript MSDN › http://teamserver:8080/tfs/DefaultCollection/!Ba cklog/_boards