LNS Home
JavaScript OSA
JavaScript OSA Home
Download & Installation
QuickStart
Project Status
Documentation
 
Object Reference
 
Core
MacOS
MacOS.AEDesc
MacOS.AEApp
MacOS.AEClass
MacOS.AEColl
MacOS.FileSpec
MacOS.OSA
MacOS.MacOSError
Sending Raw AppleEvents
Responding to AppleEvents
AppleEvent to JavaScript Value Conversion
How-Tos
 
Open Handler
Folder Actions Handlers
Write Some Text
Calling JavaScript from REALbasic
Using JavaScript Libraries
FAQ
Mailing List
JavaScript Language Documentation & Links
Products
x Script Debugger 4.5
Site Contents
bullet Mark’s Blog
Product Registration
Bug Reporting
x Freeware
Contacting Us

Using JavaScript Libraries

JavaScript libraries are blocks of code that another script can load when it needs them. To load a library you use the Core.load() function:

var lib = Core.load(Core.home + "Lib.js");
lib.f("param1", "param2"); // calls the 'f' function in Lib.js

Library scripts are stored as text files and may contain any valid JavaScript code. When JavaScript for OSA loads a library, it does the following:

  1. Reads the text file
  2. Compiles the library
  3. Executes the library
  4. Returns the result of the library script as the value of the Core.load() function
In this way, JavaScript for OSA allows you to do pretty much anything you like in libraries. The recommended approach is to have the script library return an object containing a series of functions for the client script to call.

Lib.js:

function func1(p1, p2) {
    // do something with p1 and p2
}

var obj = {f:func1};
obj; // return the "loaded" object

 

 

 

 

 


Copyright © 1998-2009 Late Night Software Ltd. - All Rights Reserved.