For the time being I'll document it here. When someone is happy with that documentation we can lift it out into the code.
The world argument is the this object - the object in which the step definition method will execute.
The intention is to avoid leaking state between scenarios. Each scenario creates new objects for each scenario, and invokes step definition methods or closures in the context of one of those objects.
Whether to create a single world object or several ones will depend on the programming language.
For JavaScript - a single object would be sufficient, since Function.apply allows executing any function with an arbitrary this object. (Unless the function is anonymous using the () => {} syntax, but that's a different issue).
For Java however, we'll use Method.invoke, which requires the object to be an instance of the class where the method is defined. So we'll need an object for each class hosting stepdef methods.
For Python I believe func.__call__ will be used, and the first argument will be a thisArg object similar to JavaScript that can be shared across stepdef functions in several files.
Maybe it's better to name the object thisObject?
Is this clearer now? (ref cucumber/common#8 (comment))
For the time being I'll document it here. When someone is happy with that documentation we can lift it out into the code.
The
worldargument is thethisobject - the object in which the step definition method will execute.The intention is to avoid leaking state between scenarios. Each scenario creates new objects for each scenario, and invokes step definition methods or closures in the context of one of those objects.
Whether to create a single
worldobject or several ones will depend on the programming language.For JavaScript - a single object would be sufficient, since Function.apply allows executing any function with an arbitrary
thisobject. (Unless the function is anonymous using the() => {}syntax, but that's a different issue).For Java however, we'll use Method.invoke, which requires the object to be an instance of the class where the method is defined. So we'll need an object for each class hosting stepdef methods.
For Python I believe
func.__call__will be used, and the first argument will be a thisArg object similar to JavaScript that can be shared across stepdef functions in several files.Maybe it's better to name the object
thisObject?Is this clearer now? (ref cucumber/common#8 (comment))