Browse Source

Update Components-js.md

This change makes more clear what is going on and why the code will not work as expected.

Even though it was already written there, I was still unsure and I have almost posted a _[Question]_. But upon re-reading what I wrote ten more times, I finally understood what you meant by `but be aware of a string conversion,`.
pull/2479/head
Vítězslav Ackermann Ferko 6 years ago
committed by GitHub
parent
commit
c7febbf03c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      docs/modules/Components-js.md

4
docs/modules/Components-js.md

@ -68,7 +68,7 @@ As you see the editor attaches a unique ID to all components with scripts and re
Keep in mind that all component scripts are executed only inside the iframe of the canvas (isolated, just like your final template), and therefore are NOT part of the current `document`. All your external libraries (eg. jQuery) are not there, but you'll see later how to manage scripted components with dependencies.
One thing you might be concerned about is a string used for the `script`, definitely not the best way to deal with a code, for this reason GrapesJS is able also to handle functions for you, so the previous example might look like this:
One thing you might be concerned about is a string used for the `script`. Definitely not the best way to deal with a code, for this reason GrapesJS is also able to handle functions for you, so the previous example might look like this:
```js
editor.BlockManager.add('test-block', {
@ -82,7 +82,7 @@ editor.BlockManager.add('test-block', {
}
});
```
This is much better, but be aware of a string conversion, you can't use variables outside of the function scope. Take a look at this scenario:
This is much better, but be aware though, that the function body is converted to string internally, before it can be placed in the document, so you can't use variables outside of the function scope. Take a look at this scenario:
```js
var myVar = 'John';

Loading…
Cancel
Save