Reputation: 267330
How can I verify if a function was defined already?
Will this work?
if(window.opener.MyFunctionBlah) { ... }
Upvotes: 1
Views: 362
Reputation: 3219
if (typeof yourFunctionName === 'function') {
yourFunctionName();
}
Upvotes: 6
Reputation: 19251
Yes. Functions are just properties of objects like any other, so you can treat them as such. The conditional you posted above will return true if that function (or any member of window.opener
called MyFunctionBlah
) is defined and non-null.
Upvotes: 2