Comments (9)
from velocity.js.
看了下,从 0.3.4 开始有这个问题
from velocity.js.
出现这个问题是因为我在内部开放出this.eval
用于解析vm字符串,在调用context和macros的方法的时候,把this指向了velocityjs对象 src/compile/references.js#L200 。
如果不改变context里面函数对应的this上线文,那么在函数里面就没法调用this.eval方法了。
from velocity.js.
我想到一个稍微麻烦一些的方案是,只对特定的函数改变其中的this,比如你需要调用this.eval来执行velocityjs解析,那么你的context里面需要有一个方法,比如名字也是eval。
比如这样:
var velocity = require('../code/velocity.js/');
var data = 'a = $a.get()';
function b(c) {
this.c = c;
}
b.prototype.get = function() {
// this 指向的是b
return this.c;
};
b.prototype.eval = function(str){
// this 指向的是Velocity.Compile
return this.eval(str);
};
var property = velocity.render(data, {
a: new b(1)
});
console.log(property);
from velocity.js.
能否不改变 this,而是增加到属性上?比如所有的 this 上都增加个 eval,只要不重名。
from velocity.js.
var that = this;
ret.eval = function(str) {
that.eval(str)
}
ret = ret.apply(ret, args);
如果只使用一个 eval 方法的话,是否可以这样
from velocity.js.
嗯,这个方案比较好,我在context传入之初就给context增加一个eval方法。
from velocity.js.
好了,我发布了一下0.3.9版本,并且增加了测试用例
from velocity.js.
修改神速 👍
from velocity.js.
Related Issues (20)
- Dashes in Identifiers HOT 1
- Support format quiet syntax $!{reference}
- String.replace() is not global HOT 2
- Map.remove() is not implemented HOT 2
- String pipe symbol not implemented HOT 1
- Support the $util.qr directive HOT 1
- IE or older browsers not supported!!! HOT 1
- Bug with #set inside #foreach: setting properties on loop variable from foreach doesn't work HOT 1
- TypeError: Cannot read property 'charCodeAt' of undefined HOT 1
- 如何实现webpack的热更新? HOT 2
- String matches does not work HOT 2
- 变量名称是null时报错 HOT 1
- Bug with rendering #foreach and $util.map.copyAndRemoveAllKeys HOT 13
- How to figure out which references in AST are able to be set in context HOT 2
- Support method with arguments HOT 2
- Parse String to Int HOT 2
- ESM module build? HOT 10
- #set with array fails for unknown reason HOT 1
- 无法解析vue中使用element-ui的$message语法 HOT 1
- Date functions not working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from velocity.js.