将变量写入相同的javascript文件

Write variable into same javascript file

本文关键字:javascript 文件 变量      更新时间:2023-09-26

我有

var world = 'here are positions of the blocks and character Mario';

我想将"Mario"更改为另一个角色(例如,"Luigi")。

var res = world.replace("Mario", "Luigi");

现在我需要写代码(res)与世界和改变字符到这个文件被引擎加载。

    window._world = {
  id: 3,
  tiles: [],
  x: 0,
  y: 0,
  tileWidth: 32,
  tileHeight: 32,
  width: 212,
  height: 17,
  backgroundColor: "rgba(66, 66, 255, 1)",
  name: "level_1-1",
  sprites: [
**Here I need write the variable res with changed character**
 ],

我该怎么做?

我以为你在期待这件事:

var world = 'here are positions of the blocks and character mario';
var res = world.replace("mario", "luigi");
window._world = {
   id: 3,
   tiles: [],
   x: 0,
   y: 0,
  tileWidth: 32,
  tileHeight: 32,
  width: 212,
  height: 17,
  backgroundColor: "rgba(66, 66, 255, 1)",
  name: "level_1-1",
 sprites: [res]
}
console.log(window._world)