Closed cowboyd closed 9 years ago
I was just about to submit a PR for the data bug :smile:
heh, yeah. I was seriously going bug-eyed over that :/
btw, if you want to communicate in real time, I'm hanging out in https://gitter.im/cowboyd/therubyracer
I'm not sure I understand what the templates are for... What is the difference with Function
?
Great question, and my knowledge of them is dated three years ago, so please take everything I'm about to say with a grain of salt.
They're like a factory for churning out pre-configured object instances. The objects have their prototype
, constructor
properties configured automatically depending on how you have them set up. This mainly helped in the old version of the ruby racer when it came to representing Ruby inheritance hierarchies inside JavaScript. So each Ruby class got its own FunctionTemplate, and then we used the Inherit
to make the JavaScript prototype chain lined up with the Ruby class hierarchy.
We might be able to get away with it using just Object and Function, but for some reason I remember it was hard to do.
Thank you for the explanation! What baffles me now is "There can only be one function created from a FunctionTemplate in a context." -- from the FunctionTemplate
docs. Why is a template useful if you can only have one function from it? Is it used for the same function across different contexts?
Yes, I think you use it to create one function in each context that you will be executing it in. That way, you can keep the meta-configuration for a function, i.e. where it fits in the prototype / constructor chain, static, but get a unique instance for each context.
This forms the basis for
ObjectTemplate
andFunctionTemplate
while at the same time fixing a bug in the Function callback where data was not getting passed