Skip to content

Commit 76b74cf

Browse files
SequoiaIgorMinar
authored andcommitted
docs(guide/concepts): removing confusing use of hoisting
Closes angular#6207
1 parent e645f7c commit 76b74cf

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

docs/content/guide/concepts.ngdoc

+19-17
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,20 @@ Let's refactor our example and move the currency conversion into a service in an
195195
<file name="finance2.js">
196196
angular.module('finance2', [])
197197
.factory('currencyConverter', function() {
198-
var currencies = ['USD', 'EUR', 'CNY'],
199-
usdToForeignRates = {
198+
var currencies = ['USD', 'EUR', 'CNY'];
199+
var usdToForeignRates = {
200200
USD: 1,
201201
EUR: 0.74,
202202
CNY: 6.09
203203
};
204+
var convert = function (amount, inCurr, outCurr) {
205+
return amount * usdToForeignRates[outCurr] * 1 / usdToForeignRates[inCurr];
206+
}
207+
204208
return {
205209
currencies: currencies,
206210
convert: convert
207211
};
208-
209-
function convert(amount, inCurr, outCurr) {
210-
return amount * usdToForeignRates[outCurr] * 1 / usdToForeignRates[inCurr];
211-
}
212212
});
213213
</file>
214214
<file name="invoice2.js">
@@ -325,21 +325,15 @@ The following example shows how this is done with Angular:
325325
var YAHOO_FINANCE_URL_PATTERN =
326326
'http://query.yahooapis.com/v1/public/yql?q=select * from '+
327327
'yahoo.finance.xchange where pair in ("PAIRS")&format=json&'+
328-
'env=store://datatables.org/alltableswithkeys&callback=JSON_CALLBACK',
329-
currencies = ['USD', 'EUR', 'CNY'],
330-
usdToForeignRates = {};
331-
refresh();
332-
return {
333-
currencies: currencies,
334-
convert: convert,
335-
refresh: refresh
336-
};
328+
'env=store://datatables.org/alltableswithkeys&callback=JSON_CALLBACK';
329+
var currencies = ['USD', 'EUR', 'CNY'];
330+
var usdToForeignRates = {};
337331

338-
function convert(amount, inCurr, outCurr) {
332+
var convert = function (amount, inCurr, outCurr) {
339333
return amount * usdToForeignRates[outCurr] * 1 / usdToForeignRates[inCurr];
340334
}
341335

342-
function refresh() {
336+
var refresh = function() {
343337
var url = YAHOO_FINANCE_URL_PATTERN.
344338
replace('PAIRS', 'USD' + currencies.join('","USD'));
345339
return $http.jsonp(url).success(function(data) {
@@ -351,6 +345,14 @@ The following example shows how this is done with Angular:
351345
usdToForeignRates = newUsdToForeignRates;
352346
});
353347
}
348+
349+
refresh();
350+
351+
return {
352+
currencies: currencies,
353+
convert: convert,
354+
refresh: refresh
355+
};
354356
}]);
355357
</file>
356358
<file name="index.html">

0 commit comments

Comments
 (0)