From ec900cabfc9d49e502b474e85f387737396e70b8 Mon Sep 17 00:00:00 2001 From: Sequoia McDowell Date: Mon, 10 Feb 2014 16:01:29 -0500 Subject: docs(guide/concepts): removing confusing use of hoisting Closes #6207 --- docs/content/guide/concepts.ngdoc | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'docs/content/guide/concepts.ngdoc') 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 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]; - } }); @@ -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 + }; }]); -- cgit v1.2.3