From 5da1acd1318195e22fbb784acc7c5486c82e49d7 Mon Sep 17 00:00:00 2001 From: Sequoia McDowell Date: Mon, 10 Feb 2014 16:01:29 -0500 Subject: [PATCH] removing confusing use of hoisting Why do ``` var ... return exports; function for exports... another function for exports... ``` Why put return statement in the middle? This "hoisting hack" makes the code harder to read and will likely confuse beginners not familiar with the concept. Unless there's some really good reason to nest the return statement between properties & methods it should not be thus. --- docs/content/guide/concepts.ngdoc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/content/guide/concepts.ngdoc b/docs/content/guide/concepts.ngdoc index 9581514df7f3..0ec2f295e115 100644 --- a/docs/content/guide/concepts.ngdoc +++ b/docs/content/guide/concepts.ngdoc @@ -195,20 +195,23 @@ Let's refactor our example and move the currency conversion into a service in an angular.module('finance2', []) .factory('currencyConverter', function() { + var currencies = ['USD', 'EUR', 'CNY'], usdToForeignRates = { USD: 1, EUR: 0.74, CNY: 6.09 }; + + function convert(amount, inCurr, outCurr) { + return amount * usdToForeignRates[outCurr] * 1 / usdToForeignRates[inCurr]; + } + return { currencies: currencies, convert: convert }; - - function convert(amount, inCurr, outCurr) { - return amount * usdToForeignRates[outCurr] * 1 / usdToForeignRates[inCurr]; - } + }); @@ -329,12 +332,7 @@ The following example shows how this is done with Angular: currencies = ['USD', 'EUR', 'CNY'], usdToForeignRates = {}; refresh(); - return { - currencies: currencies, - convert: convert, - refresh: refresh - }; - + function convert(amount, inCurr, outCurr) { return amount * usdToForeignRates[outCurr] * 1 / usdToForeignRates[inCurr]; } @@ -351,6 +349,13 @@ The following example shows how this is done with Angular: usdToForeignRates = newUsdToForeignRates; }); } + + return { + currencies: currencies, + convert: convert, + refresh: refresh + }; + }]);