How do I address an object value in a whose clause in AppleScript I am trying to test a object property of elements in a whose clause.

For example, let's use the common elements "document" and "window" that almost every Mac app has:

tell application "TextEdit"
    get document 1 --&gt; document "Untitled"
    get window 1 --&gt; window id 40640
    get document of window 1 --&gt; document "Untitled"
end tell


So we see that window 1 has a document property that points back to a document element.

Now I like to find all documents that are in window 1 (please don't question the sense of this - while it makes little sense in this particular case, I need the solution for a different case where it's actually useful). I try this:

set theDoc to document of window 1 --&gt; document "Untitled"
get every window whose document is theDoc


But that fails with the error Can’t make document into type reference. number -1700 from document to reference.

How do I solve this without resolving to a loop command (repeat), but staying with the whose clause?
Use its or of it, like this:

tell application "TextEdit"
    set theDoc to document of window 1
    get every window whose its document is theDoc
    -- or --&gt; get every window whose document of it is theDoc
end tell