Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pt-br: Format /web/javascript using Prettier (part 4) #14828

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,36 @@ Object.getOwnPropertyNames(obj)
### Usando `Object.getOwnPropertyNames()`

```js
var arr = ['a', 'b', 'c'];
var arr = ["a", "b", "c"];
console.log(Object.getOwnPropertyNames(arr).sort());
// logs ["0", "1", "2", "length"]

// Array-like object
var obj = { 0: 'a', 1: 'b', 2: 'c' };
var obj = { 0: "a", 1: "b", 2: "c" };
console.log(Object.getOwnPropertyNames(obj).sort());
// logs ["0", "1", "2"]

// Logging property names and values using Array.forEach
Object.getOwnPropertyNames(obj).forEach(function(val, idx, array) {
console.log(val + ' -> ' + obj[val]);
Object.getOwnPropertyNames(obj).forEach(function (val, idx, array) {
console.log(val + " -> " + obj[val]);
});
// logs
// 0 -> a
// 1 -> b
// 2 -> c

// non-enumerable property
var my_obj = Object.create({}, {
getFoo: {
value: function() { return this.foo; },
enumerable: false
}
});
var my_obj = Object.create(
{},
{
getFoo: {
value: function () {
return this.foo;
},
enumerable: false,
},
},
);
my_obj.foo = 1;

console.log(Object.getOwnPropertyNames(my_obj).sort());
Expand All @@ -64,19 +69,19 @@ Se voce quer somente as propriedades enumeráveis, veja {{jsxref("Object.keys()"

```js
function ParentClass() {}
ParentClass.prototype.inheritedMethod = function() {};
ParentClass.prototype.inheritedMethod = function () {};

function ChildClass() {
this.prop = 5;
this.method = function() {};
this.method = function () {};
}
ChildClass.prototype = new ParentClass;
ChildClass.prototype.prototypeMethod = function() {};
ChildClass.prototype = new ParentClass();
ChildClass.prototype.prototypeMethod = function () {};

console.log(
Object.getOwnPropertyNames(
new ChildClass() // ["prop", "method"]
)
new ChildClass(), // ["prop", "method"]
),
);
```

Expand All @@ -88,7 +93,7 @@ Isto usa a função {{jsxref("Array.prototype.filter()")}} para remover as chave
var target = myObject;
var enum_and_nonenum = Object.getOwnPropertyNames(target);
var enum_only = Object.keys(target);
var nonenum_only = enum_and_nonenum.filter(function(key) {
var nonenum_only = enum_and_nonenum.filter(function (key) {
var indexInEnum = enum_only.indexOf(key);
if (indexInEnum == -1) {
// not found in enum_only keys mean the key is non-enumerable,
Expand All @@ -107,19 +112,19 @@ console.log(nonenum_only);
No ES5, se o argumento desse método não é um objeto (um tipo primitivo), então isso causará um {{jsxref("TypeError")}}. No ES6, um argumento diferente de objeto será transformado em um objeto.

```js
Object.getOwnPropertyNames('foo');
Object.getOwnPropertyNames("foo");
// TypeError: "foo" is not an object (ES5 code)

Object.getOwnPropertyNames('foo');
Object.getOwnPropertyNames("foo");
// ["0", "1", "2", "length"] (ES6 code)
```

## Especificações

| Esperificação | Status | Comentário |
| -------------------------------------------------------------------------------------------------------------------- | ---------------------------- | ---------------------------------------------------- |
| {{SpecName('ES5.1', '#sec-15.2.3.4', 'Object.getOwnPropertyNames')}} | {{Spec2('ES5.1')}} | Definição inicial. Implementado no JavaScript 1.8.5. |
| {{SpecName('ES6', '#sec-object.getownpropertynames', 'Object.getOwnPropertyNames')}} | {{Spec2('ES6')}} | |
| Esperificação | Status | Comentário |
| ---------------------------------------------------------------------------------------- | -------------------- | ---------------------------------------------------- |
| {{SpecName('ES5.1', '#sec-15.2.3.4', 'Object.getOwnPropertyNames')}} | {{Spec2('ES5.1')}} | Definição inicial. Implementado no JavaScript 1.8.5. |
| {{SpecName('ES6', '#sec-object.getownpropertynames', 'Object.getOwnPropertyNames')}} | {{Spec2('ES6')}} | |
| {{SpecName('ESDraft', '#sec-object.getownpropertynames', 'Object.getOwnPropertyNames')}} | {{Spec2('ESDraft')}} | |

## Compatibilidade com navegadores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ O **`Object.getOwnPropertySymbols()`** método retorna uma array com todas propr
## Sintaxe

```js
Object.getOwnPropertySymbols(obj)
Object.getOwnPropertySymbols(obj);
```

### Parâmetro
Expand All @@ -36,23 +36,23 @@ Como todos os objetos não possuem símbolos próprios inicialmente, o `Object.g

```js
var obj = {};
var a = Symbol('a');
var b = Symbol.for('b');
var a = Symbol("a");
var b = Symbol.for("b");

obj[a] = 'localSymbol';
obj[b] = 'globalSymbol';
obj[a] = "localSymbol";
obj[b] = "globalSymbol";

var objectSymbols = Object.getOwnPropertySymbols(obj);

console.log(objectSymbols.length); // retorno esperado 2
console.log(objectSymbols); // retorno esperado (2) [Symbol(a), Symbol(b)]
console.log(objectSymbols[0]); // retorno esperado Symbol(a)
console.log(objectSymbols); // retorno esperado (2) [Symbol(a), Symbol(b)]
console.log(objectSymbols[0]); // retorno esperado Symbol(a)
```

## Especificações

| Especificação |
| ---------------------------------------------------------------------------------------------------------------------------- |
| Especificação |
| -------------------------------------------------------------------------------------------- |
| {{SpecName('ESDraft', '#sec-object.getownpropertysymbols', 'Object.getOwnPropertySymbols')}} |

## Compatibilidade com navegadores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Object.getPrototypeOf("foo");

## Especificação

| Especificação | Status | Comentário |
| ------------------------------------------------------------------------------------------------ | ------------------------ | ------------------ |
| {{SpecName('ES5.1', '#sec-15.2.3.2', 'Object.getPrototypeOf')}} | {{Spec2('ES5.1')}} | definição inicial. |
| {{SpecName('ES6', '#sec-object.getprototypeof', 'Object.getProtoypeOf')}} | {{Spec2('ES6')}} | |
| Especificação | Status | Comentário |
| ------------------------------------------------------------------------- | ------------------ | ------------------ |
| {{SpecName('ES5.1', '#sec-15.2.3.2', 'Object.getPrototypeOf')}} | {{Spec2('ES5.1')}} | definição inicial. |
| {{SpecName('ES6', '#sec-object.getprototypeof', 'Object.getProtoypeOf')}} | {{Spec2('ES6')}} | |

## Compatibilidade com navegadores

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ O seguinte exemplo diferencia entre propriedade diretas e propriedade herdadas d

```js
o = new Object();
o.prop = 'existe';
o.hasOwnProperty('prop'); // Retorna true
o.hasOwnProperty('toString'); // Retorna false
o.hasOwnProperty('hasOwnProperty'); // Retorna false
o.prop = "existe";
o.hasOwnProperty("prop"); // Retorna true
o.hasOwnProperty("toString"); // Retorna false
o.hasOwnProperty("hasOwnProperty"); // Retorna false
```

### Percorrer através das propriedades de um objeto
Expand All @@ -75,16 +75,15 @@ Vale observar que o loop {{jsxref("Statements/for...in", "for...in")}} percorre

```js
var buz = {
fog: 'stack'
fog: "stack",
};

for (var nome in buz) {
if (buz.hasOwnProperty(nome)) {
alert("this is fog (" + nome + ") for sure. Value: " + buz[nome]);
}
else {
alert(nome); // toString ou qualquer outra coisa
}
if (buz.hasOwnProperty(nome)) {
alert("this is fog (" + nome + ") for sure. Value: " + buz[nome]);
} else {
alert(nome); // toString ou qualquer outra coisa
}
}
```

Expand All @@ -94,30 +93,30 @@ JavaScript não protege o nome `hasOwnProperty`, assim, se existir a possibilida

```js
var foo = {
hasOwnProperty: function() {
return false;
},
bar: 'Here be dragons'
hasOwnProperty: function () {
return false;
},
bar: "Here be dragons",
};

foo.hasOwnProperty('bar'); // Sempre retorna false
foo.hasOwnProperty("bar"); // Sempre retorna false

// Usando a propriedade hasOwnProperty de outro objeto e definindo 'this' como foo
({}).hasOwnProperty.call(foo, 'bar'); // true
({}).hasOwnProperty.call(foo, "bar"); // true

// Também é possível usar hasOwnProperty do objeto
Object.prototype.hasOwnProperty.call(foo, 'bar'); // true
Object.prototype.hasOwnProperty.call(foo, "bar"); // true
```

Observe que neste ultimo caso nenhum novo objeto é criado.

## Especificações

| Especificação | Status | Comentário |
| ---------------------------------------------------------------------------------------------------------------------------- | ------------------------ | ------------------ |
| ECMAScript 3rd Edition. Implemented in JavaScript 1.5 | Standard | Definição inicial. |
| {{SpecName('ES5.1', '#sec-15.2.4.5', 'Object.prototype.hasOwnProperty')}} | {{Spec2('ES5.1')}} | |
| {{SpecName('ES6', '#sec-object.prototype.hasownproperty', 'Object.prototype.hasOwnProperty')}} | {{Spec2('ES6')}} | |
| Especificação | Status | Comentário |
| ---------------------------------------------------------------------------------------------- | ------------------ | ------------------ |
| ECMAScript 3rd Edition. Implemented in JavaScript 1.5 | Standard | Definição inicial. |
| {{SpecName('ES5.1', '#sec-15.2.4.5', 'Object.prototype.hasOwnProperty')}} | {{Spec2('ES5.1')}} | |
| {{SpecName('ES6', '#sec-object.prototype.hasownproperty', 'Object.prototype.hasOwnProperty')}} | {{Spec2('ES6')}} | |

## Compatibilidade com navegadores

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ var o = new Object(Boolean());

## Especificações

| Especificações | Status | Comentário |
| ---------------------------------------------------------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------- |
| {{SpecName('ES1')}} | {{Spec2('ES1')}} | Definição inicial. Implementado no JavaScript 1.0. |
| {{SpecName('ES5.1', '#sec-15.2', 'Object')}} | {{Spec2('ES5.1')}} | ------------------------------------------------ |
| {{SpecName('ES6', '#sec-object-objects', 'Object')}} | {{Spec2('ES6')}} | Adicionado `Object.assign`, `Object.getOwnPropertySymbols`, `Object.setPrototypeOf` e `Object.is` |
| Especificações | Status | Comentário |
| -------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------- |
| {{SpecName('ES1')}} | {{Spec2('ES1')}} | Definição inicial. Implementado no JavaScript 1.0. |
| {{SpecName('ES5.1', '#sec-15.2', 'Object')}} | {{Spec2('ES5.1')}} | ------------------------------------------------ |
| {{SpecName('ES6', '#sec-object-objects', 'Object')}} | {{Spec2('ES6')}} | Adicionado `Object.assign`, `Object.getOwnPropertySymbols`, `Object.setPrototypeOf` e `Object.is` |
| {{SpecName('ESDraft', '#sec-object-objects', 'Object')}} | {{Spec2('ESDraft')}} | Adicionado `Object.entries`, `Object.values` e `Object.getOwnPropertyDescriptors`. |

## Compatibilidade
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ Isso também _não_ _é_ o mesmo que ser igual de acordo com o operador {{jsxref
## Exemplos

```js
Object.is('foo', 'foo'); // true
Object.is(window, window); // true
Object.is("foo", "foo"); // true
Object.is(window, window); // true

Object.is('foo', 'bar'); // false
Object.is([], []); // false
Object.is("foo", "bar"); // false
Object.is([], []); // false

var test = { a: 1 };
Object.is(test, test); // true
Object.is(test, test); // true

Object.is(null, null); // true
Object.is(null, null); // true

// Casos especiais
Object.is(0, -0); // false
Object.is(-0, -0); // true
Object.is(NaN, 0/0); // true
Object.is(0, -0); // false
Object.is(-0, -0); // true
Object.is(NaN, 0 / 0); // true
```

## Polyfill para navegadores que não suportam ES6
Expand All @@ -70,9 +70,10 @@ Object.is(NaN, 0/0); // true

```js
if (!Object.is) {
Object.is = function(x, y) {
Object.is = function (x, y) {
// Algoritmo para verificar se os valores sao iguais
if (x === y) { // Passos 1-5, 7-10
if (x === y) {
// Passos 1-5, 7-10
// Passos 6.b-6.e: +0 != -0
return x !== 0 || 1 / x === 1 / y;
} else {
Expand All @@ -85,9 +86,9 @@ if (!Object.is) {

## Especificações

| Especificação | Status | Comentário |
| ------------------------------------------------------------------------ | ---------------------------- | ------------------ |
| {{SpecName('ES6', '#sec-object.is', 'Object.is')}} | {{Spec2('ES6')}} | Definição inicial. |
| Especificação | Status | Comentário |
| ------------------------------------------------------ | -------------------- | ------------------ |
| {{SpecName('ES6', '#sec-object.is', 'Object.is')}} | {{Spec2('ES6')}} | Definição inicial. |
| {{SpecName('ESDraft', '#sec-object.is', 'Object.is')}} | {{Spec2('ESDraft')}} | |

## Compatibilidade com navegadores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ Object.isExtensible(1);

## Especificações

| Especificações | Status | Comentário |
| ---------------------------------------------------------------------------------------------------- | ---------------------------- | ---------------------------------------------------- |
| {{SpecName('ES5.1', '#sec-15.2.3.13', 'Object.isExtensible')}} | {{Spec2('ES5.1')}} | Initial definition. Implemented in JavaScript 1.8.5. |
| {{SpecName('ES6', '#sec-object.isextensible', 'Object.isExtensible')}} | {{Spec2('ES6')}} | |
| Especificações | Status | Comentário |
| -------------------------------------------------------------------------- | -------------------- | ---------------------------------------------------- |
| {{SpecName('ES5.1', '#sec-15.2.3.13', 'Object.isExtensible')}} | {{Spec2('ES5.1')}} | Initial definition. Implemented in JavaScript 1.8.5. |
| {{SpecName('ES6', '#sec-object.isextensible', 'Object.isExtensible')}} | {{Spec2('ES6')}} | |
| {{SpecName('ESDraft', '#sec-object.isextensible', 'Object.isExtensible')}} | {{Spec2('ESDraft')}} | |

## Compatibilidade com navegadores
Expand Down
Loading