亚洲国产日韩欧美在线a乱码,国产精品路线1路线2路线,亚洲视频一区,精品国产自,www狠狠,国产情侣激情在线视频免费看,亚洲成年网站在线观看

從零碼起調(diào)用javascript

時(shí)間:2025-11-01 06:21:43 java語(yǔ)言

從零碼起調(diào)用javascript

  Java語(yǔ)言作為靜態(tài)面向?qū)ο缶幊陶Z(yǔ)言的代表,極好地實(shí)現(xiàn)了面向?qū)ο罄碚摚试S程序員以優(yōu)雅的思維方式進(jìn)行復(fù)雜的編程。以下是小編為大家搜索整理的從零碼起調(diào)用javascript,希望能給大家?guī)韼椭?更多精彩內(nèi)容請(qǐng)及時(shí)關(guān)注我們應(yīng)屆畢業(yè)生考試網(wǎng)!

  package co.test;

  import java.io.FileReader;

  import java.io.LineNumberReader;

  import org.mozilla.javascript.Context;

  import org.mozilla.javascript.Function;

  import org.mozilla.javascript.Scriptable;

  public class JSExploration

  {

  private Context cx;

  private Scriptable scope;

  public JSExploration()

  {

  this.cx = Context.enter();

  this.scope = cx.initStandardObjects();

  }

  public Object runJavaScript(String filename)

  {

  String jsContent = this.getJsContent(filename);

  Object result = cx.evaluateString(scope, jsContent, filename, 1, null);

  return result;

  }

  private String getJsContent(String filename)

  {

  LineNumberReader reader;

  try

  {

  reader = new LineNumberReader(new FileReader(filename));

  String s = null;

  StringBuffer sb = new StringBuffer();

  while ((s = reader.readLine()) != null)

  {

  sb.append(s).append("\n");

  }

  return sb.toString();

  }

  catch (Exception e)

  {

  /pic/p>

  e.printStackTrace();

  return null;

  }

  }

  public Scriptable getScope()

  {

  return scope;

  }

  public static void main(String[] args)

  {

  String filename = System.getProperty("user.dir") + "/jsmap.js";

  JSExploration jsExploration = new JSExploration();

  Object result = jsExploration.runJavaScript(filename);

  Scriptable scope = jsExploration.getScope();

  Function sum = (Function) scope.get("sum", scope);

  Function isPrime = (Function)sum.call(Context.getCurrentContext(), scope, sum, new Object[] {2,8});

  Object ss = isPrime.call(Context.getCurrentContext(), sum, isPrime, new Object[] {2,8});

  System.out.println(Context.toString(ss));

  }

  }

  試驗(yàn)了一個(gè)java 調(diào)用 javascript 的例子,如果把jsmap.js中的與this 有關(guān)的代碼注銷的話程序就可以正常運(yùn)行。不住銷掉的話就會(huì)報(bào)個(gè)運(yùn)行時(shí)錯(cuò)誤。。。

  js 代碼如下(有關(guān)this 的代碼已注銷):

  function sum(x, y) {

  /pic/p>

  /pic/p>

  /pic/2;

  /pic/p>

  var vager = 1000;

  return function (x,y){return x + y + vager;} ;

  }

【從零碼起調(diào)用javascript】相關(guān)文章:

java調(diào)用的方法10-22

JavaScript的應(yīng)用01-04

PHP調(diào)用的C代碼08-27

匯編調(diào)用C函數(shù)02-02

java調(diào)用的幾個(gè)方法09-29

如何調(diào)用其他PPT01-19

系統(tǒng)調(diào)用的概念簡(jiǎn)介11-17

iframe調(diào)用父頁(yè)面方法01-24

C語(yǔ)言函數(shù)的運(yùn)用及調(diào)用09-27