[指令碼語言][RINGO JS]模組 globals
阿新 • • 發佈:2018-11-07
模組 globals
RingoJS 採用了 Rhino shell 的一些 global 屬性並增加了一些屬性。
請注意,該模組必須和不能像普通模組一樣匯入。 RingoJS 啟動時僅評估一次。
Functions
- addToClasspath (path)
- clearInterval (id)
- clearTimeout (id)
- defineClass (clazz)
- export (name...)
- gc ()
- getRepository (path)
- getResource
- include (moduleId)
- load (filename...)
- module.resolve (path)
- module.singleton (id, factory)
- print (args...)
- privileged (func)
- quit ()
- require (moduleId)
- seal (obj)
- setInterval (callback, delay, args...)
- setTimeout
- spawn (func)
- sync (func, [obj])
Properties
- arguments
- console
- environment
- exports
- global
- module
- module.directory
- module.exports
- module.id
- module.path
- module.uri
- require.extensions
- require.main
- require.paths
addToClasspath (path)
在執行時將路徑新增到 RingoJS 應用程式類路徑。如果庫及其類不在預設的 Java 類路徑中,這是必需的。
呼叫 addToClasspath() 將呼叫 org.ringojs.engine.AppClassLoader,它是 java.net.URLClassLoader 的子類。它檢查 URL 是否已經被載入,如果沒有,則將其新增到資源搜尋路徑。如果給定的 URL 以/結尾,則它將被視為資源目錄,否則將被視為引用 .jar 檔案。 .jar 檔案封裝了不同包中的各種 .class 檔案,而資源目錄是 JVM 的任意 .class 查詢的起點。如果函式無法載入路徑或失敗,則該函式將引發異常。
Example
// Adds Apache Lucene text search engine to the classpath
addToClasspath("../jars/lucene-core.jar");