mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-29 05:15:38 +08:00
style(*): wrap all assignments in if statements
we commonly assign stuff in if statments like this:
if (variable = someFn()) {
//do something with variable
}
This results in lint and IDE warnings (did you mean ==?).
It is better to be explicit about our intention and wrap the assignement
into parens:
if ((variable = someFn())) {
//do something with variable
}
Doing so suppresses warnings + is easier to understand the intention.
I verified that the closure compiler strips the extra parens, so there
is no byte overhead for this safety practice.
We should use this style going forward...
This commit is contained in:
@@ -216,7 +216,7 @@ angularServiceInject('$route', function($location) {
|
||||
// Match a route
|
||||
forEach(routes, function(rParams, rPath) {
|
||||
if (!pathParams) {
|
||||
if (pathParams = matcher($location.hashPath, rPath)) {
|
||||
if ((pathParams = matcher($location.hashPath, rPath))) {
|
||||
selectedRoute = rParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $error, $log) {
|
||||
|
||||
if (method == 'GET') {
|
||||
var data, dataCached;
|
||||
if (dataCached = cache.data[url]) {
|
||||
if ((dataCached = cache.data[url])) {
|
||||
|
||||
if (sync) {
|
||||
success(200, copy(dataCached.value));
|
||||
@@ -64,7 +64,7 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $error, $log) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data = inflight[url]) {
|
||||
if ((data = inflight[url])) {
|
||||
data.successes.push(success);
|
||||
data.errors.push(error);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user