最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Accessing a MooTools Class Method from outside the class - Stack Overflow

programmeradmin2浏览0评论

I have a method inside of a MooTools class that I want to access after uploading a file with AJAX (iFrame). The Javascript that the iFrame page runs when it loads should call the method of the Class, but I am unable to access it using anything like: Class name: Main var class was initialized in: myMain

parent.window.myMain.myMethod parent.window.Main.myMethod

Is this even possible? If it is how do I do this?

I have a method inside of a MooTools class that I want to access after uploading a file with AJAX (iFrame). The Javascript that the iFrame page runs when it loads should call the method of the Class, but I am unable to access it using anything like: Class name: Main var class was initialized in: myMain

parent.window.myMain.myMethod parent.window.Main.myMethod

Is this even possible? If it is how do I do this?

Share Improve this question asked Jul 24, 2009 at 15:42 trobrocktrobrock 47.4k11 gold badges41 silver badges47 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 10

The syntax I prefer:

var MyClass = new Class({

  /* list regular non-static methods her as usual */

});

MyClass.staticMethod = function()
{
   /* body of static function */
};

The advantages you have are:

  • You can call the static method via MyClass.staticMethod() inside and outside of your class
  • It is not possible to accidentally access the this-pointer in the static method as it is not available

To access the static method in an inner frame use can window.parent.MyClass.staticMethod();

This works for me (iframes too).

In main window.

var T=new MyClass();

In Iframe (which loads after T was initialized!)

window.parent.T.anyMethodOfMyClass()

Just figured it out. On the iFrame page, I need to use:

window.parent.Main.prototype.myMethod();

Might not be the proper way of accessing it, but it works.

发布评论

评论列表(0)

  1. 暂无评论