简体   繁体   中英

Add function to firefox extension Javascript file

I am actually working on a Firefox extension and I am trying to create objects containing both variables and methods in seperate Javascript files. So I tried to declare the instance like this :

var options = {
  toto: null,

  ready: function() {
    console.log("Foo");
  }
};

And when I try to console.log(options); it only displays {toto:null} And if I try to call the ready function it says ready is not declared.

What do I do wrong?

Thank you in advance

 Have tried the same code in chrome.
 There seems to be no issue with the Object creation. 

Attaching the image for reference.

在此处输入图片说明

Object is displaying both 'todo' and 'ready' as its propery in console,and we can access them using 'Object.propertyName' in your case :

'options.todo' and 'options.ready()'

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