Having written a ton of web applications using JSON / AJAX, I find that I am returning exact literal javascript objects (JSON). For example, I can request all cats from GetCats.asp. He will return:
[
{'id': 0, 'name': 'Persian'},
{'id': 1, 'name': 'Calico'},
{'id': 2, 'name': 'Tabby'}
]
Now these are all Cat objects with behavior. However, if I define a Cat object, the Cat () {} function, I donโt know an EFFECTIVE way to persuade these literals in the behavior of the user object.
I can do this by brute-force iterating through them and assigning functions, but that won't be pretty. Is there a good, one line (or several) way to somehow "distinguish" this behavior from these literals?
zenon3
source
share