使用javascript api向手写笔添加自定义函数
我想将charAt js函数添加到stylus,我尝试了stylus文档中发布的示例,如下所示:使用javascript api向手写笔添加自定义函数,javascript,stylus,Javascript,Stylus,我想将charAt js函数添加到stylus,我尝试了stylus文档中发布的示例,如下所示: var stylus = require('./node_modules/stylus') , nodes = stylus.nodes , utils = stylus.utils , fs = require('fs'); function charAt(string, index) { return string.charAt(index); } stylus(str) .set
var stylus = require('./node_modules/stylus')
, nodes = stylus.nodes
, utils = stylus.utils
, fs = require('fs');
function charAt(string, index) {
return string.charAt(index);
}
stylus(str)
.set('filename', 'js-functions')
.define('charAt', charAt)
.render(function(err, css){
if (err) throw err;
console.log(css);
});
我将require路径更改为我的手写笔dir和insidetest.styl
我有以下功能:
use('js-functions.js')
当我运行它时,请注意以下错误:
ReferenceError: test.styl:1
> 1| use("js-functions.js")
2|
3|
4|
str is not defined
这里发生了什么?我遗漏了什么?这些文档没有很好地解释给刚接触node和stylus的人。创建一个文件“test.js”,如下所示:
var plugin = function(){
return function(style){
style.define('charAt', function (string, index) {
})
}
}
module.exports = plugin;
手写笔代码:
use('test.js')
创建一个文件“test.js”,如下所示:
var plugin = function(){
return function(style){
style.define('charAt', function (string, index) {
})
}
}
module.exports = plugin;
手写笔代码:
use('test.js')
创建一个文件“test.js”,如下所示:
var plugin = function(){
return function(style){
style.define('charAt', function (string, index) {
})
}
}
module.exports = plugin;
手写笔代码:
use('test.js')
创建一个文件“test.js”,如下所示:
var plugin = function(){
return function(style){
style.define('charAt', function (string, index) {
})
}
}
module.exports = plugin;
手写笔代码:
use('test.js')