diff options
| author | Sequoia McDowell | 2014-02-10 16:01:29 -0500 | 
|---|---|---|
| committer | Igor Minar | 2014-02-10 16:19:10 -0800 | 
| commit | ec900cabfc9d49e502b474e85f387737396e70b8 (patch) | |
| tree | 1c12a457d6cff351102c270ea4b63a1e825ff360 | |
| parent | f99fe799e29f691783ebdd604debfbbd0da80f6b (diff) | |
| download | angular.js-ec900cabfc9d49e502b474e85f387737396e70b8.tar.bz2 | |
docs(guide/concepts): removing confusing use of hoisting
Closes #6207
| -rw-r--r-- | docs/content/guide/concepts.ngdoc | 36 | 
1 files changed, 19 insertions, 17 deletions
| diff --git a/docs/content/guide/concepts.ngdoc b/docs/content/guide/concepts.ngdoc index 4c870804..d964da7e 100644 --- a/docs/content/guide/concepts.ngdoc +++ b/docs/content/guide/concepts.ngdoc @@ -195,20 +195,20 @@ Let's refactor our example and move the currency conversion into a service in an    <file name="finance2.js">      angular.module('finance2', [])        .factory('currencyConverter', function() { -        var currencies = ['USD', 'EUR', 'CNY'], -            usdToForeignRates = { +        var currencies = ['USD', 'EUR', 'CNY']; +        var usdToForeignRates = {            USD: 1,            EUR: 0.74,            CNY: 6.09          }; +        var convert = function (amount, inCurr, outCurr) { +          return amount * usdToForeignRates[outCurr] / usdToForeignRates[inCurr]; +        } +          return {            currencies: currencies,            convert: convert          }; - -        function convert(amount, inCurr, outCurr) { -          return amount * usdToForeignRates[outCurr] / usdToForeignRates[inCurr]; -        }        });    </file>    <file name="invoice2.js"> @@ -325,21 +325,15 @@ The following example shows how this is done with Angular:          var YAHOO_FINANCE_URL_PATTERN =                'http://query.yahooapis.com/v1/public/yql?q=select * from '+                'yahoo.finance.xchange where pair in ("PAIRS")&format=json&'+ -              'env=store://datatables.org/alltableswithkeys&callback=JSON_CALLBACK', -            currencies = ['USD', 'EUR', 'CNY'], -            usdToForeignRates = {}; -        refresh(); -        return { -          currencies: currencies, -          convert: convert, -          refresh: refresh -        }; +              'env=store://datatables.org/alltableswithkeys&callback=JSON_CALLBACK'; +        var currencies = ['USD', 'EUR', 'CNY']; +        var usdToForeignRates = {}; -        function convert(amount, inCurr, outCurr) { +        var convert = function (amount, inCurr, outCurr) {            return amount * usdToForeignRates[outCurr] / usdToForeignRates[inCurr];          } -        function refresh() { +        var refresh = function() {            var url = YAHOO_FINANCE_URL_PATTERN.                       replace('PAIRS', 'USD' + currencies.join('","USD'));            return $http.jsonp(url).success(function(data) { @@ -351,6 +345,14 @@ The following example shows how this is done with Angular:              usdToForeignRates = newUsdToForeignRates;            });          } + +        refresh(); + +        return { +          currencies: currencies, +          convert: convert, +          refresh: refresh +        };        }]);    </file>    <file name="index.html"> | 
