Re: function javascript in all cell
Matthias Bussonnier <[email protected]> Fri, 23 Dec 2016 17:45:46 +0100
| Newsgroups | gmane.comp.python.ipython.user |
|---|---|
| Message-ID | <CANJQusVmNkRg=vvUNZ+0DwH64OavcMtrFoAy3Zo2xJrFN_9fcQ@mail.gmail.com> |
Hi debimax, First I'd like to let you know that ipython-user is deprecated and ipython-dev(at)scipy.org is prefered we tend not to segregate devs and user. If you are advanced enough to code in IPython, you are advanced enough to modify it. Also if english is not your prefered language and you need to ask some pieces in another language, feel free to do so, I myself started here a couple of years ago barely able to align two words, and probably still do a lot of mistakes. The reason for the behavior you see is that each of the javascript cell is executed in a different context in which locals and globals are different. `element` is a magic element which is injected. So when you execute things in the first cell, what you defined there will not exist in others unless you explicitly attach it to a global object. Usually in JS you will attach to the `window` object (If I Remember correctly). So if you do something like `window.afficher = afficher`, then it should work, `afficher` will be search in the global namespace if not found locally. Hope that helps. -- Matthias On Fri, Dec 23, 2016 at 9:17 AM, debimax <[email protected]> wrote: > hello > > (excuse me for my bad english) > Il have un function in cell javascript > > cell1: ************************** > %%javascript > function afficher(msg) > { > element.append(msg); > } > afficher("hi") > ******************************** > > > it's good and i have message "hi" but if i try function afficher in a > other cell > cell2: *************************** > %%javascript > afficher("hi") > ********************************* > > it's no good and i have error: *<it> NameError: name 'afficher' is not > defined</it>* > > is it possible to use function /afficher/ in all cell. > > thanks > > > > -- > View this message in context: http://python.6.x6.nabble.com/function-javascript-in-all-cell-tp5205651.html > Sent from the IPython - User mailing list archive at Nabble.com. > _______________________________________________ > IPython-User mailing list > [email protected] > https://mail.scipy.org/mailman/listinfo/ipython-user