我想将charAt js函数添加到手写笔中,我尝试在手写文档中发布的示例如下所示:
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);
});我将需求路径更改为我的手写笔dir,在test.styl中我有以下内容:
use('js-functions.js')当我运行它时,请接受以下错误:
ReferenceError: test.styl:1
> 1| use("js-functions.js")
2|
3|
4|
str is not defined这里发生了什么?,我缺少了什么?,对于刚接触节点和手写笔的人来说,文档并不能很好地解释它。
发布于 2014-04-08 09:48:57
创建一个像这样的文件“test.js”:
var plugin = function(){
return function(style){
style.define('charAt', function (string, index) {
})
}
}
module.exports = plugin;手写笔代码:
use('test.js')https://stackoverflow.com/questions/22836972
复制相似问题