Brief introduction:
This function returns the debug string:
Number,boolean,string,null,undefined, it will be converted to a string.
Functions with spaces in front of the parentheses will remove the function body, without spaces, and will output all the contents of the function. If you want to get rid of the function body without any spaces, change to/*\{[\s\s]*/
The object is converted to a JSON string, and if attribute a in the object and property B point to the same object, then that property becomes .... If the value is Window,document,scope, the property in the object will be converted to $window, $DOCUMENT, $SCOPE.
It can be found from the source code that json.stringify can turn Null,boolean,number into a string.
Json.stringify's detailed introduction can be seen here: http://www.cnblogs.com/ningvsban/p/3660654.html
functiontodebugstring (obj) {if(typeofobj = = = ' function ') { //A regular expression that removes the function body, for example: function A () {var i = 0;}, which is filtered into function a () //This regular expression is very wonderful, if () there is no space or a number of spaces, it will not remove the function body, change to the following ///*\{[\s\s]*/ //to match, and what's the use of $? returnObj.tostring (). replace (/\{[\s\s]*$/, '); }Else if(isundefined (obj)) {return' Undefined '; } Else if(typeofObj!== ' string ') { returnserializeobject (obj); } returnobj;}
Test code:
Console.log (todebugstring (1)); Console.log (Todebugstring (true)); Console.log (Todebugstring (Uncle)); Console.log (Todebugstring (NULL)); Console.log (todebugstring (undefined)); Console.log (Todebugstring (function(){ varName = "function with no spaces in front of brackets, preserve function body"; })); Console.log (Todebugstring (functionA () {varName = "function with spaces in front of brackets"; })); varobj = {name: "Uncle"}; varA = todebugstring (NULL); Console.log (todebugstring ({name:"Uncle", Window:window,document:document,height:obj,width:obj}));
Output content:
1
True
Uncle
Null
Undefined
function () {
var name = "Function with no spaces in front of brackets, retain function body";
}
function A ()
{"Name": "Uncle", "window": "$WINDOW", "Document": "$DOCUMENT", "height": {"name": "Uncle"}, "width": "..."}
AngularJS Source read one: todebugstring