One, JavaScript lazy function
FUNCTION CREATEXHR () {var xhr = null;try{//firefox,opera 8.0+,safari,ie7+xhr = new xmlhttprequest ();} catch (E) {//internet explorertry{xhr = new activexobject ("msxml2.xmlhttp");} catch (E) {try{xhr = new activexobject ("Microsoft.XMLHTTP");} catch (e) {xhr = null;}}} RETURN XHR;} Function handleerr (err) {//var errxhr = err;////}/* lazy function *///Second effective FUNCTION CREATEXHR () {var xhr = null;if (typeof xmlhttprequest != ' undefined ') {xhr = new xmlhttprequest (); Createxhr = function () {return new xmlhttprequest ();}} Else{try{xhr = new activexobject ("Msxml2.xmlhttp"); Createxhr = function () {return new activexobject ("Msxml2.xmlhttp");}} catch (E) {try{xhr = new activexobject ("Microsoft.XMLHTTP"); Createxhr = function () { Return new activexobject ("Microsoft.XMLHTTP");}} catch (e) {CREATEXHR () = function () {return null;}}} RETURN XHR;}
Second, the function of the branch.
Function Curry (FN) {var args = Array.prototype.slice.call (arguments,1); return function () {var Innerargs = Array.prototype.slice.call (arguments); var Finalargs = Args.concat (Innerargs); Console.log (Finalargs); return Fn.apply (This,finalargs);}} function Add (num1,num2,num3) {return num1+num2+num3;} var t = Curry (add,50), alert (t);
Three, cascading functions
function ClassA () {this.face = ""; this.mouse = ""; This.leg = "";} Classa.prototype = {setface:function () {this.face = "cheeked";} Setmouse:function () {this.mouse = "big Mouth";} Setleg:function () {This.leg = "long legged Aubagne";}}; var person = new ClassA ();p erson.setface ();p erson.setmouse ();p Erson.setleg (), console.log (person);
JavaScript advanced functions