Skip to content

Commit aea4869

Browse files
committed
updating pt_BR
1 parent 2b6e592 commit aea4869

File tree

1 file changed

+57
-26
lines changed

1 file changed

+57
-26
lines changed

translations/pt_BR/readme.md

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Projetos _devem_ incluir alguma forma de teste unitário, de referência, de imp
9292
* [Hiro](http://hirojs.com/)
9393
* [JsTestDriver](https://code.google.com/p/js-test-driver/)
9494
* [Buster.js](http://busterjs.org/)
95+
* [Sinon.js](http://sinonjs.org/)
9596

9697
## Índice
9798

@@ -1120,57 +1121,87 @@ As seções a seguir descrevem um guia de estilos razoável para desenvolvimento
11201121
}
11211122

11221123
// 7.A.1.2
1123-
// Um caso melhor seria utilizar um objeto literal ou até um módulo:
1124+
// Uma maneira alternativa de dar suporte para facilidade de composição e
1125+
// reutiilização é utilizar um objeto que guarde "cases" e uma função
1126+
// para delegar:
11241127

1125-
var switchObj = {
1128+
var cases, delegator;
1129+
1130+
// Retornos de exemplo apenas para ilustração.
1131+
cases = {
11261132
alpha: function() {
11271133
// instruções
11281134
// um retorno
1135+
return [ "Alpha", arguments.length ];
11291136
},
11301137
beta: function() {
11311138
// instruções
11321139
// um retorno
1140+
return [ "Beta", arguments.length ];
11331141
},
11341142
_default: function() {
11351143
// instruções
11361144
// um retorno
1145+
return [ "Default", arguments.length ];
11371146
}
11381147
};
11391148

1140-
var switchModule = (function () {
1141-
return {
1142-
alpha: function() {
1143-
// instruções
1144-
// um retorno
1145-
},
1146-
beta: function() {
1147-
// instruções
1148-
// um retorno
1149-
},
1150-
_default: function() {
1151-
// instruções
1152-
// um retorno
1153-
}
1154-
};
1155-
})();
1149+
delegator = function() {
1150+
var args, key, delegate;
1151+
1152+
// Transforma a lista de argumentos em uma array
1153+
args = [].slice.call( arguments );
1154+
1155+
// Retira a chave inicial dos argumentos
1156+
key = args.shift();
11561157

1158+
// Atribui o manipulador de caso padrão
1159+
delegate = cases._default;
1160+
1161+
// Deriva o método para delegar a operação para
1162+
if ( cases.hasOwnProperty( key ) ) {
1163+
delegate = cases[ key ];
1164+
}
1165+
1166+
// O argumento de escopo pode ser definido para algo específico
1167+
// nesse caso, |null| será suficiente
1168+
return delegate.apply( null, args );
1169+
};
11571170

11581171
// 7.A.1.3
1159-
// Se `foo` é uma propriedade de `switchObj` ou `switchModule`, execute-a como um método...
1172+
// Coloque a API do 7.A.1.2 para funcionar:
1173+
1174+
delegator( "alpha", 1, 2, 3, 4, 5 );
1175+
// [ "Alpha", 5 ]
1176+
1177+
// Claro que a argumento de chave inicial pode ser facilmente baseada
1178+
// em alguma outra condição arbitrária.
1179+
1180+
var caseKey, someUserInput;
1181+
1182+
// Possivelmente alguma maneira de entrada de formulário?
1183+
someUserInput = 9;
1184+
1185+
if ( someUserInput > 10 ) {
1186+
caseKey = "alpha";
1187+
} else {
1188+
caseKey = "beta";
1189+
}
11601190

1161-
( Object.hasOwnProperty.call( switchObj, foo ) && switchObj[ foo ] || switchObj._default )( args );
1191+
// ou...
11621192

1163-
( Object.hasOwnProperty.call( switchObj, foo ) && switchModule[ foo ] || switchModule._default )( args );
1193+
caseKey = someUserInput > 10 ? "alpha" : "beta";
11641194

1165-
// Se você conhece e confia no valor de `foo`, você pode inclusive omitir a checagem `OR`
1166-
// deixando apenas a execução:
1195+
// E assim...
11671196

1168-
switchObj[ foo ]( args );
1197+
delegator( caseKey, someUserInput );
1198+
// [ "Beta", 1 ]
11691199

1170-
switchModule[ foo ]( args );
1200+
// E claro...
11711201

1202+
delegator();
1203+
// [ "Default", 0 ]
11721204

1173-
// Esse padrão também promove a reutilização de código
11741205

11751206
```
11761207

0 commit comments

Comments
 (0)