1 /*gets a specified length random number*/2Csdn.random =function(len) {3 if(!len) len = 5;4 varR =math.random (). toString ();5 returnR.substr (R.length-len);6 };7 8 9 /*determine if the URL contains a string s*/TenCsdn.urlhas =function(s) { One returnWindow.location.href.toLowerCase (). IndexOf (S.tolowercase ()) > 0; A }; - - the - /*obtaining a user name from a cookie*/ -Csdn.getun =function () { - varm = Document.cookie.match (NewRegExp ("(^|) Username= ([^;] *)(;|$)")); + if(m)returnM[2]; - Else return‘‘; + }; A at - functionformatbytes (bytes) { - vars = [' Byte ', ' KB ', ' MB ', ' GB ', ' TB ', ' PB ']; - varE = Math.floor (Math.log (bytes)/Math.log (1024)); - return(Bytes/math.pow (1024x768, Math.floor (e))). ToFixed (2) +S[e]; - } in functionReturnfalse () {return false; } - } to + - //The typeof operator returns a string that is used to represent the data type of the expression. the functionIsoptionalvalue (value) { * return typeof(value) = = = ' Undefined ' | | Value = =NULL; $}
JavaScript-Encapsulated functions