zoukankan      html  css  js  c++  java
  • locutus(phpjs) 的使用

    今天来介绍一个js的框架,这个框架的主要功能呢,是通过加载该类库,来实现php函数的调用

    当然了,这并不是说php中所有的函数都能在js中使用,但很大一部分是可以的。

    环境:mac + node v5.9.0 + npm 3.7.3 + webstorm

    1. 首先,我们的环境需要安装node,安装nodejs 就不在此赘述

    2.接下来,需要我们安装 locutus 类库,一般国外的镜像较慢,我们这里使用taobao的镜像

    npm --registry=https://registry.npm.taobao.org install locutus -g
    

     需要注意的是,-g 在这里表示全局安装,这样的话,在你的电脑上就可以随处访问了

    3.安装成功后,就可以使用了,在webstrom 中,创建一个空项目,新建文件 locutus.php.js, 具体代码如下

    var echo = require('locutus/php/strings/echo')   //使用php库echo 方法  
    var capwords = require('locutus/python/string/capwords')    //使用python string库
    var strings = require('locutus/golang/strings') //使用go strings 方法
    var rubyMath = require('locutus/ruby/Math')    //使用ruby库Math方法
    var c = require('locutus/c')  //使用c语言库
    
    echo('hello locutus');
    
    echo(capwords('hello locutus'))
    
    echo(strings.Contains('Locutus','us'))
    
    echo(rubyMath.acos(0.3))
    
    echo(c.math.abs(-3))    
    

    可以看到,需要注意的点在于 locutus 的require

    好了,就介绍至此

      

  • 相关阅读:
    cf C. Vasya and Robot
    zoj 3805 Machine
    cf B. Vasya and Public Transport
    cf D. Queue
    cf C. Find Maximum
    cf B. Two Heaps
    cf C. Jeff and Rounding
    cf B. Jeff and Periods
    cf A. Jeff and Digits
    I Think I Need a Houseboat
  • 原文地址:https://www.cnblogs.com/zeopean/p/5962700.html
Copyright © 2011-2022 走看看