Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Constructor, operator "new"#273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
10 commits
Select commitHold shift + click to select a range
c019820
traducción Object.keys
EzequielCasteJun 22, 2020
9e6442f
Update 1-js/04-object-basics/06-constructor-new/2-calculator-construc…
EzequielCasteJun 28, 2020
e7d5068
Update 1-js/04-object-basics/06-constructor-new/article.md
EzequielCasteJun 28, 2020
993dea0
Update 1-js/04-object-basics/06-constructor-new/article.md
EzequielCasteJun 28, 2020
381668b
Update 1-js/04-object-basics/06-constructor-new/article.md
EzequielCasteJun 28, 2020
0e4a7c7
Update 1-js/04-object-basics/06-constructor-new/article.md
EzequielCasteJun 28, 2020
619b0cb
Update 1-js/04-object-basics/06-constructor-new/article.md
EzequielCasteJun 28, 2020
23c506a
Update 1-js/04-object-basics/06-constructor-new/3-accumulator/task.md
EzequielCasteJun 28, 2020
3d556ea
Update 1-js/04-object-basics/06-constructor-new/3-accumulator/task.md
EzequielCasteJun 28, 2020
a6dbf35
Update 1-js/04-object-basics/06-constructor-new/3-accumulator/task.md
EzequielCasteJun 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
Yes, it's possible.
Si, es posible.

If a function returns an object then `new`returns it instead of `this`.
Si una función devuelve un objeto, entonces `new`lo devuelve en vez de `this`.

So they can, for instance, return the same externally defined object `obj`:
Por lo tanto pueden, por ejemplo, devolver el mismo objeto definido externamente `obj`:

```js run no-beautify
let obj = {};
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,9 @@ importance: 2

---

#Two functionsone object
#Dos funcionesun objeto

Is it possible to create functions`A`and `B`such as `new A()==new B()`?
Es posible crear las funciones`A`y `B`como `new A()==new B()`?

```js no-beautify
function A() { ... }
Expand All@@ -16,4 +16,4 @@ let b = new B;
alert( a == b ); // true
```

If it is, then provide an example of their code.
Si es posible, entonces proporcione un ejemplo de su código.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,11 +11,11 @@ describe("calculator", function() {
calculator.read();
});

it("when 2 and 3 are entered, the sum is 5", function() {
it("cuando se ingresa 2 y 3, la suma es 5", function() {
assert.equal(calculator.sum(), 5);
});

it("when 2 and 3 are entered, the product is 6", function() {
it("cuando se ingresa 2 y 3, el producto es 6", function() {
assert.equal(calculator.mul(), 6);
});

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,15 +2,15 @@ importance: 5

---

#Create new Calculator
#Crear nueva Calculadora

Create a constructor function `Calculator`that creates objects with 3methods:
Crear una función constructora `Calculator`que crea objetos con 3métodos:

- `read()`asks for two values using`prompt`and remembers them in object properties.
- `sum()`returns the sum of these properties.
- `mul()`returns the multiplication product of these properties.
- `read()`pide dos valores usando`prompt`y los recuerda en las propiedades del objeto.
- `sum()`devuelve la suma de estas propiedades.
- `mul()`devuelve el producto de multiplicación de estas propiedades.

For instance:
Por ejemplo:

```js
let calculator = new Calculator();
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,23 +8,23 @@ describe("Accumulator", function() {
prompt.restore();
});

it("initial value is the argument of the constructor", function() {
it("valor inicial es el argumento del constructor", function() {
let accumulator = new Accumulator(1);

assert.equal(accumulator.value, 1);
});

it("after reading0,the value is 1", function() {
it("después de leer0,el valor es 1", function() {
let accumulator = new Accumulator(1);
prompt.returns("0");
accumulator.read();
assert.equal(accumulator.value, 1);
});

it("after reading1,the value is 2", function() {
it("después de leer1,el valor es 2", function() {
let accumulator = new Accumulator(1);
prompt.returns("1");
accumulator.read();
assert.equal(accumulator.value, 2);
});
});
});
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ function Accumulator(startingValue) {
this.value = startingValue;

this.read = function() {
this.value += +prompt('How much to add?', 0);
this.value += +prompt('Cuánto más agregar?', 0);
};

}
Expand Down
22 changes: 11 additions & 11 deletions1-js/04-object-basics/06-constructor-new/3-accumulator/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,26 +2,26 @@ importance: 5

---

#Create new Accumulator
#Crear nuevo Acumulador

Create a constructor function `Accumulator(startingValue)`.
Crear una función contructor `Accumulator(startingValue)`.

Object that it creates should:
El objeto que crea debería:

-Store the "current value" in the property `value`.The starting value is set to the argument of the constructor `startingValue`.
-The`read()`method should use`prompt`to read a new number and add it to `value`.
-Almacene el "valor actual" en la propiedad `value`.El valor inicial se establece en el argumento del constructor `startingValue`.
-El método`read()`debe usar`prompt`para leer un nuevo número y agregarlo a `value`.

In other words, the`value`property is the sum of all user-entered values with the initial value `startingValue`.
En otras palabras, la propiedad`value`es la suma de todos los valores ingresados por el usuario con el valor inicial `startingValue`.

Here's the demo of the code:
Aquí está la demostración del código:

```js
let accumulator = new Accumulator(1); //initial value 1
let accumulator = new Accumulator(1); //valor inicial 1

accumulator.read(); //adds the user-entered value
accumulator.read(); //adds the user-entered value
accumulator.read(); //agrega el valor introducido por el usuario
accumulator.read(); //agrega el valor introducido por el usuario

alert(accumulator.value); //shows the sum of these values
alert(accumulator.value); //muestra la suma de estos valores
```

[demo]
Loading

[8]ページ先頭

©2009-2025 Movatter.jp