简体   繁体   中英

How to trigger parent's function?

I have this code:

function someFunction () {
  alert('fired!')
}
var options = [
  {selector: 'footer', offset: 50, callback: 'someFunction()' },
];
Materialize.scrollFire(options);

I'm getting an error Uncaught ReferenceError: someFunction is not defined

I do understand why it happens, but i can't get, how should i trigger someFunction anyway?

ps. if i change 'someFunction()' to alert('fired!') , alert happens.

Just change it to a reference to the function:

var options = [
  {
    ...
    callback: someFunction
];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM