Skip to content Skip to sidebar Skip to footer

How Can I Add A Function To Json Object Which Has __type Attribute?

I am sending an object that i generated within a class from the server as a result of web service call. it is returning with __type and it's other attributes from server. I wan

Solution 1:

Well if I get you right, you want to add a function() to the returned object. You can't add a function serverside, since you are not allowed to transfer executable javascript code within a JSON object.

So you would have to add a method/property to that object after your client has created your javascript object. like

success: function(data){
   data.my_new_method = function(){
      // yay!
   }
},

Post a Comment for "How Can I Add A Function To Json Object Which Has __type Attribute?"