![]() |
Please tell me how to compare two JSObjects.
I want a sample program which tells me comparision between two JSObjects. Any help would be really appreciated.
Thanks, Suraj G |
If you just want to check if both names point to the same object then:
Code:
if (obj1 === obj2)Code:
if (JSON.stringify(obj1) === JSON.stringify(obj2)) |
Code:
import java.io.*; |
Sorry, the last post was hidden in the moderation queue. However, this is JAVA, not JavaScript. Keep that in mind for the next time, sur_7887. I’m moving it to the correct forum.
|
Since JSObject is not a built in interface, you'll need to modify the JSObject interface and add an extension of type
Comparable<JSObject> to it.This will force you to implement CompareTo so you can compare two objects of the same type and return 0 if its equal, < 0 if "other" is < "this", and > 0 if "this" is > "other". You need to write what it compares of course. This can then be used in any collection type to sort, or used manually with jsobject1.compareTo(jsobject2). Not sure exactly what it will do if you use it in anonymous inner classes with a collection, but I presume it will work. |
| All times are GMT +1. The time now is 07:53 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.