मैं Google Apps स्क्रिप्ट का उपयोग करके टूलसेट बनाने में देख रहा था। इसके साथ समस्या यह है कि जहां तक मैं कह सकता हूं केवल एक स्तर के संगठन की अनुमति देता है। आप स्टॉपवॉच नामक एक लाइब्रेरी बना सकते हैं और कॉल विधियों Stopwatch.start() और Stopwatch.stop() को कॉल कर सकते हैं जो बहुत अच्छा है।Google Apps स्क्रिप्ट लाइब्रेरी में नामस्थान जैसी संगठन बनाना
जो मुझे दिमाग में था, हालांकि कुछ ऐसा था जैसे Utils.Stopwatch()। Start() और Utils.Timer.start() आदि। मुझे लगता है कि यह जावास्क्रिप्ट में निश्चित रूप से संभव है, लेकिन ऐप्स स्क्रिप्ट को स्वतः पूर्ण करने के लिए एक निश्चित प्रारूप में इसे जोड़ने की जरूरत है। नीचे उदाहरण गलत करने का एक उदाहरण है (एक त्रुटि देता है) लेकिन शायद कुछ समय बचाता है। यह this आलेख पर आधारित है।
/**
* A stopwatch object.
* @return {Object} The stopwatch methods
*/
function Stopwatch()
{
var current;
/**
* Stop the stopwatch.
* @param {Time} time in miliseconds
*/
function timeInSeconds_(time)
{
return time/1000;
}
return
{
/**
* Start the stopwatch.
*/
start: function()
{
var time = new Date().getTime();
current = timeInSeconds_(time);
},
/**
* Stop the stopwatch.
* @return {decimal} time passed since calling
* start (in seconds)
*/
stop: function()
{
var time = new Date().getTime();
var difference = timeInSeconds_(time) - this.current;
return difference.toFixed(3);
}
};
}
धन्यवाद
मैं आप अनुमान लगा इस मामले में कोड कर रहे हैं हो सकता है 'Utils.Stopwatch() शुरू()' – Eduardo
सही, मेरा बुरा –