c3js / c3

:bar_chart: A D3-based reusable chart library
http://c3js.org
MIT License
9.34k stars 1.39k forks source link

C3 problem (bind "this" to nested API) when used with Angular #2388

Open mpycio opened 6 years ago

mpycio commented 6 years ago

I'm getting an error when using this library in Angular project, I'm providing c3js as an injectable service and seem that Angular adds a property called __anonymousType to target function. When binding this to target chart inside `function Chart' on line 1047 this causes an error:

ERROR TypeError: fn[key].bind is not a function
at c3.js:1047
at Array.forEach (<anonymous>)
at bindThis (c3.js:1046)
at c3.js:1049
at Array.forEach (<anonymous>)
at bindThis (c3.js:1046)
at new Chart (c3.js:1052)

Can a simple check be added fn[key].hasOwnProperty('bind') or similar to prevent binding this to any property that other libs may be injecting, this is also future proofing code is some props are not a fn.

mpycio commented 6 years ago

This gets even worse on the following line where this is assigned recursively as this injected prop is a string.. getting a stack overflow. I had to add typeof fn[key] === 'function' check