makeZoneSpec
A function that returns a ZoneSpec object. This can be used any place where a ZoneSpec is accepted.
function(data)
Parameters
- data
{data}
:The Zone's data object, useful when you want to append data to the Zone.
This examples wraps document.createElement to keep count of how many elements are created, and appends the count to data when the Zone ends.
var mySpec = function(data){ var realCreateElement, count = 0; return { beforeTask: function(){ realCreateElement = document.createElement; document.createElement = function(){ count++; return realCreateElement.apply(this, arguments); }; }, afterTask: function(){ document.createElement = realCreateElement; }, ended: function(){ data.elementsCreated = count; } }; }; var zone = new Zone(mySpec); zone.run(function(){ // Do stuff here }) .then(function(data){ data.elementsCreated; // -> 5 });
Using a function rather than a ZoneSpec object gives you a closure where you can store local variables that will be specific to the Zone you are running in.