- Download and Install
- Interactive Code Evaluation
- Running Tests on a Web browser
Download and Install
PharoJS is freely available under MIT License. Install can be done inside Pharo 4.0 by evaluating the following in a playground:
smalltalkhubUser: 'noury' project: 'PharoJS';
addPackage: #ConfigurationOfPharoJS ;
This will install the latest stable version.
Interactive Code Evaluation
First launch PharoJS workspace, by evaluating the following expression in a plain workspace or GT playground:
workspace := JbWorkspaceForWeb open.
This will open pink workspace, this is the current PharoJS workspace. It also launches a server on Pharo side and opens a web browser that is connected to the server. Now, you can evaluate a simple Smalltalk expression such as 1+2, and see it performing on the web browser (see Figure 1).
counter := JbCounter new.
Note: When you load a class, you need obviously to load also all classes it uses, and its superclass. But, here the superclass is JbObject which is the root class of PharoJS classes. It is loaded by default when you open the workspace, because the code to support the PharoJS workspace is written in PharoJS itself :-)
Running Tests on a Web browser
JbBridgeTest. Add the following
bridge loadClass: JbCounter.
bridge eval: 'counter := JbCounter new'.
Let’s write a test method. Consider the following one:
bridge eval: '20 timesRepeat: [counter increment]'.
self assertSmalltalk: 'counter count' equalsJson: '20'
We first make the bridge evaluate an expression on the browser (
eval: message). Then we check that the Smalltalk expression
The full code of the test is available in the Example category of the PharoJS project. You can run it using the TestRunner of Pharo. You’ll see the web browser blinking openning/closing a tab or a window for every test method.
How do you integrate HTML/CSS files from a web designer into a PharoJS application?
document native_getElementById: 'someId'
JbDemoApplication exportToFile: 'demo.js'
The start method of an app may also introduce extra globals that will be referenced in the HTML or any other pure JS library. This can be done using the follwing message, that is understood by any PharoJS object
install: anObject asGlobalNamed: jsName
Your JS file from PharoJS should be imported together with other JS libraries in your HTML. In your PharoJS code, you need to global objects introduced by your libraries as entry points to JS libraries. All you need is to declare them using
For questions, please post them as comments to the current page. For further more information, please get in touch with Noury.