Search code examples
javascriptcallbackpopupparent-childparent

javascript call class from popup window


is there a way to callback a class object from popup window.

i know there is way to callback a function:

window.opener.MyFunction();

but i want to know, how to call class method

new Profile('me', 'id');

im not sure how to do it, but just to give you idea

window.opener.'new Profile('me', 'id');';

yes i know, its not valid js code, but its just to give you idea :)


Solution

  • Profile is a property of window.opener.
    You can use it like any other property:

    new window.opener.Profile(...);
    

    new is an operator that acts on a function; you can use it with any expression that returns a function.
    You can even write

    new (function() { ...}) (...);
    

    For more pathological corner cases of this behavior, see this answer.