开发者_如何学PythonI have a Web Service and it always brings back one object from my class that i defined on the server side.
in success method of $.ajax function i always get the this object. And on the client side i want to add couple of functions to display its properties quickier.
Is there a way do that ? (JSON object will return, i am worrying about that)
You can extend javascript objects and add methods to it:
var json = { name: 'john' };
json.print = function() {
    alert('my name is ' + this.name);
};
json.print();
As you already told me in your last question about this topic
how can i add a function to json object which has __type attribute?
you want to have a global functionally. Since you still can't add a function into json you should declare a global function like:
var props = (function(){
   var spacing = '';
   function props(json, deep) {
      if(typeof json === 'object'){
         for(var prop in json){
             if(typeof json[prop] === 'object'){             
                spacing += '   ';
                props(json[prop], true); 
             }
             else{                
               console.log(spacing, prop, ': ', json[prop]);
             }
         }
      }
   }
   return props;
}());
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论