javascript - how to use variable on bonsai.js? -


var star = document.getelementbyid("star"); var color = "#ef6360";  bonsai.run(star, {      code: function() {          new star(30, 30, 20, 5, 0.7).attr({              fillcolor: color          }).addto(stage);      }  }); 

it doesn't work, it'll work if remove variable , directly use string, fillcolor:"#ef6360". why?

as far know, cannot access variables inside code because context has limited access browser per documentation here (read first note).

this docs exactly.

note: runner context has limited access browser functionality (e.g. no dom access) because in cases bonsai code executed in worker. therefore limited use provided bonsai api , normal js functions provided worker (see functions available workers on mdn details). if want pass initial data runner context can read @ bottom of page or if want dynamically manipulate dom through bonsai should have @ communication overview.

if there way access window scope inside web worker, possible. (i not know if possible)

hope helps.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -