In the episode "Shanghaied" on The Flying Dutchman's ship,SpongeBob and Patrick find out they're gonna get eaten,The Flying Dutchman grants them three wishes,Patrick wishes he knew that earlier,SpongeBob takes the 2nd wish and wishes for Squidward to be there.
Later The Flying Dutchman chooses who should get the last wish and it was SpongeBob,then Squidward said,"Think SpongeBob so we won't be eaten." or something like that,the point is how did Squidward know they were gonna get eaten? All they told him was The Flying Dutchman gave them three wishes.