3

Basically, there is a page that I visit that uses RequireJS. I want to make adjustments to this page, so I went the route of a userscript. While looking at the client-side code I see that there is a module defined as so:

define("settings", [], function() {
    return {
    SETTINGA: "100",
    SETTINGB: "200",
    etc.
    }
})

I want to add my own item to the settings array, as well as change some settings without having to redefine the module in my userscript (with the changes) and then removing/readding it. Is it possible to just make adjustments to this module?


P.S. I'm using the Script Injection technique to get my userscript to interact with other javascript in the original page.

Also, doing require("settings") in the Javascript console returns an object (not an array), so I can't do things like require("settings")[0] or require("settings").push(...), however I can access the settings by doing require("settings").SETTINGA. So, I'm not sure how to add/redefine settings to this since it is not an array?

4

2 回答 2

4

用这个:

require('settings').new_property = 'new value';
于 2012-06-02T23:43:13.827 回答
2

您无法检索或将设置添加到“设置数组”的原因是您没有创建一个数组开始。{foo:bar}是一个对象字面量,而不是一个数组字面量 ( [foo,bar])。

于 2014-03-27T19:29:45.820 回答