From 8f2731905212f6e7eb2d9793ad20b8b448c54ccf Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:51:31 +0100 Subject: unslug tr: move --- .../global_objects/array/prototype/index.html | 205 -------- .../global_objects/boolean/prototype/index.html | 77 --- .../global_objects/map/prototype/index.html | 85 ---- .../reference/operators/function_star_/index.html | 84 +++ .../web/javascript/reference/operators/index.html | 277 ++++++++++ .../reference/operators/instanceof/index.html | 207 ++++++++ .../reference/operators/super/index.html | 165 ++++++ .../javascript/reference/operators/this/index.html | 347 +++++++++++++ .../reference/operators/typeof/index.html | 259 ++++++++++ .../arithmetic_operators/index.html" | 294 ----------- .../bitwise_operators/index.html" | 565 --------------------- .../operat\303\266rler/function_star_/index.html" | 84 --- .../reference/operat\303\266rler/index.html" | 277 ---------- .../operat\303\266rler/instanceof/index.html" | 207 -------- .../mantiksal_operatorler/index.html" | 312 ------------ .../reference/operat\303\266rler/super/index.html" | 165 ------ .../reference/operat\303\266rler/this/index.html" | 347 ------------- .../operat\303\266rler/typeof/index.html" | 259 ---------- 18 files changed, 1339 insertions(+), 2877 deletions(-) delete mode 100644 files/tr/web/javascript/reference/global_objects/array/prototype/index.html delete mode 100644 files/tr/web/javascript/reference/global_objects/boolean/prototype/index.html delete mode 100644 files/tr/web/javascript/reference/global_objects/map/prototype/index.html create mode 100644 files/tr/web/javascript/reference/operators/function_star_/index.html create mode 100644 files/tr/web/javascript/reference/operators/index.html create mode 100644 files/tr/web/javascript/reference/operators/instanceof/index.html create mode 100644 files/tr/web/javascript/reference/operators/super/index.html create mode 100644 files/tr/web/javascript/reference/operators/this/index.html create mode 100644 files/tr/web/javascript/reference/operators/typeof/index.html delete mode 100644 "files/tr/web/javascript/reference/operat\303\266rler/arithmetic_operators/index.html" delete mode 100644 "files/tr/web/javascript/reference/operat\303\266rler/bitwise_operators/index.html" delete mode 100644 "files/tr/web/javascript/reference/operat\303\266rler/function_star_/index.html" delete mode 100644 "files/tr/web/javascript/reference/operat\303\266rler/index.html" delete mode 100644 "files/tr/web/javascript/reference/operat\303\266rler/instanceof/index.html" delete mode 100644 "files/tr/web/javascript/reference/operat\303\266rler/mantiksal_operatorler/index.html" delete mode 100644 "files/tr/web/javascript/reference/operat\303\266rler/super/index.html" delete mode 100644 "files/tr/web/javascript/reference/operat\303\266rler/this/index.html" delete mode 100644 "files/tr/web/javascript/reference/operat\303\266rler/typeof/index.html" (limited to 'files/tr/web/javascript/reference') diff --git a/files/tr/web/javascript/reference/global_objects/array/prototype/index.html b/files/tr/web/javascript/reference/global_objects/array/prototype/index.html deleted file mode 100644 index 19ffe3c80f..0000000000 --- a/files/tr/web/javascript/reference/global_objects/array/prototype/index.html +++ /dev/null @@ -1,205 +0,0 @@ ---- -title: Array.prototype -slug: Web/JavaScript/Reference/Global_Objects/Array/prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Array/prototype ---- -
{{JSRef("Global_Objects", "Array")}}
- -

Summary

- -

The Array.prototype property represents the prototype for the {{jsxref("Global_Objects/Array", "Array")}} constructor.

- -
{{js_property_attributes(0, 0, 0)}}
- -

Description

- -

{{jsxref("Global_Objects/Array", "Array")}} instances inherit from Array.prototype. As with all constructors, you can change the constructor's prototype object to make changes to all {{jsxref("Global_Objects/Array", "Array")}} instances.

- -

Little known fact: Array.prototype itself is an {{jsxref("Global_Objects/Array", "Array")}}:

- -
Array.isArray(Array.prototype); // true
-
- -

Properties

- -
-
Array.prototype.constructor
-
Specifies the function that creates an object's prototype.
-
{{jsxref("Array.prototype.length")}}
-
Reflects the number of elements in an array.
-
- -

Methods

- -

Mutator methods

- -

These methods modify the array:

- -
-
{{jsxref("Array.prototype.copyWithin()")}} {{experimental_inline}}
-
Copies a sequence of array elements within the array.
-
{{jsxref("Array.prototype.fill()")}} {{experimental_inline}}
-
Fills all the elements of an array from a start index to an end index with a static value.
-
{{jsxref("Array.prototype.pop()")}}
-
Removes the last element from an array and returns that element.
-
{{jsxref("Array.prototype.push()")}}
-
Adds one or more elements to the end of an array and returns the new length of the array.
-
{{jsxref("Array.prototype.reverse()")}}
-
Reverses the order of the elements of an array in place — the first becomes the last, and the last becomes the first.
-
{{jsxref("Array.prototype.shift()")}}
-
Removes the first element from an array and returns that element.
-
{{jsxref("Array.prototype.sort()")}}
-
Sorts the elements of an array in place and returns the array.
-
{{jsxref("Array.prototype.splice()")}}
-
Adds and/or removes elements from an array.
-
{{jsxref("Array.prototype.unshift()")}}
-
Adds one or more elements to the front of an array and returns the new length of the array.
-
- -

Accessor methods

- -

These methods do not modify the array and return some representation of the array.

- -
-
{{jsxref("Array.prototype.concat()")}}
-
Returns a new array comprised of this array joined with other array(s) and/or value(s).
-
{{jsxref("Array.prototype.includes()")}} {{experimental_inline}}
-
Determines whether an array contains a certain element, returning true or false as appropriate.
-
{{jsxref("Array.prototype.join()")}}
-
Joins all elements of an array into a string.
-
{{jsxref("Array.prototype.slice()")}}
-
Extracts a section of an array and returns a new array.
-
{{jsxref("Array.prototype.toSource()")}} {{non-standard_inline}}
-
Returns an array literal representing the specified array; you can use this value to create a new array. Overrides the {{jsxref("Object.prototype.toSource()")}} method.
-
{{jsxref("Array.prototype.toString()")}}
-
Returns a string representing the array and its elements. Overrides the {{jsxref("Object.prototype.toString()")}} method.
-
{{jsxref("Array.prototype.toLocaleString()")}}
-
Returns a localized string representing the array and its elements. Overrides the {{jsxref("Object.prototype.toLocaleString()")}} method.
-
{{jsxref("Array.prototype.indexOf()")}}
-
Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.
-
{{jsxref("Array.prototype.lastIndexOf()")}}
-
Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.
-
- -

Iteration methods

- -

Several methods take as arguments functions to be called back while processing the array. When these methods are called, the length of the array is sampled, and any element added beyond this length from within the callback is not visited. Other changes to the array (setting the value of or deleting an element) may affect the results of the operation if the method visits the changed element afterwards. While the specific behavior of these methods in such cases is well-defined, you should not rely upon it so as not to confuse others who might read your code. If you must mutate the array, copy into a new array instead.

- -
-
{{jsxref("Array.prototype.forEach()")}}
-
Calls a function for each element in the array.
-
{{jsxref("Array.prototype.entries()")}} {{experimental_inline}}
-
Returns a new Array Iterator object that contains the key/value pairs for each index in the array.
-
{{jsxref("Array.prototype.every()")}}
-
Returns true if every element in this array satisfies the provided testing function.
-
{{jsxref("Array.prototype.some()")}}
-
Returns true if at least one element in this array satisfies the provided testing function.
-
{{jsxref("Array.prototype.filter()")}}
-
Creates a new array with all of the elements of this array for which the provided filtering function returns true.
-
{{jsxref("Array.prototype.find()")}} {{experimental_inline}}
-
Returns the found value in the array, if an element in the array satisfies the provided testing function or undefined if not found.
-
{{jsxref("Array.prototype.findIndex()")}} {{experimental_inline}}
-
Returns the found index in the array, if an element in the array satisfies the provided testing function or -1 if not found.
-
{{jsxref("Array.prototype.keys()")}} {{experimental_inline}}
-
Returns a new Array Iterator that contains the keys for each index in the array.
-
{{jsxref("Array.prototype.map()")}}
-
Creates a new array with the results of calling a provided function on every element in this array.
-
{{jsxref("Array.prototype.reduce()")}}
-
Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
-
{{jsxref("Array.prototype.reduceRight()")}}
-
Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value.
-
{{jsxref("Array.prototype.values()")}} {{experimental_inline}}
-
Returns a new Array Iterator object that contains the values for each index in the array.
-
{{jsxref("Array.prototype.@@iterator()", "Array.prototype[@@iterator]()")}} {{experimental_inline}}
-
Returns a new Array Iterator object that contains the values for each index in the array.
-
- -

Generic methods

- -

Many methods on the JavaScript Array object are designed to be generally applied to all objects which “look like” Arrays. That is, they can be used on any object which has a length property, and which can usefully be accessed using numeric property names (as with array[5] indexing). TODO: give examples with Array.prototype.forEach.call, and adding the method to an object like {{jsxref("Global_Objects/JavaArray", "JavaArray")}} or {{jsxref("Global_Objects/String", "String")}}. Some methods, such as {{jsxref("Array.join", "join")}}, only read the length and numeric properties of the object they are called on. Others, like {{jsxref("Array.reverse", "reverse")}}, require that the object's numeric properties and length be mutable; these methods can therefore not be called on objects like {{jsxref("Global_Objects/String", "String")}}, which does not permit its length property or synthesized numeric properties to be set.

- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
ECMAScript 1st Edition.StandardInitial definition.
{{SpecName('ES5.1', '#sec-15.4.3.1', 'Array.prototype')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-array.prototype', 'Array.prototype')}}{{Spec2('ES6')}} 
- -

Browser compatibility

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

See also

- - diff --git a/files/tr/web/javascript/reference/global_objects/boolean/prototype/index.html b/files/tr/web/javascript/reference/global_objects/boolean/prototype/index.html deleted file mode 100644 index dcb92f48b3..0000000000 --- a/files/tr/web/javascript/reference/global_objects/boolean/prototype/index.html +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: Boolean.prototype -slug: Web/JavaScript/Reference/Global_Objects/Boolean/prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Boolean -translation_of_original: Web/JavaScript/Reference/Global_Objects/Boolean/prototype ---- -
{{JSRef}}
- -

Boolean.prototype özelliği {{jsxref ("Boolean")}} yapıcı methodunun prototipini temsil eder.

- -
{{js_property_attributes(0, 0, 0)}}
- -
{{EmbedInteractiveExample("pages/js/boolean-constructor.html")}}
- - - -

 

- -

{{jsxref("Boolean")}} instances inherit from Boolean.prototype. You can use the constructor's prototype object to add properties or methods to all {{jsxref("Boolean")}} instances.

- -

Properties

- -
-
Boolean.prototype.constructor
-
Bir örneğin prototipini oluşturan fonksiyonu döndürür. Bu varsayılan olarak {{jsxref ("Boolean")}} işlevidir.
-
- -

Methods

- -
-
{{jsxref("Boolean.prototype.toSource()")}} {{non-standard_inline}}
-
{{Jsxref ("Boolean")}} nesnesinin kaynağını içeren bir dize döndürür; eşdeğer bir nesne oluşturmak için bu dizeyi kullanabilirsiniz. {{Jsxref ("Object.prototype.toSource ()")}} methodunu geçersiz kılar.
-
{{jsxref("Boolean.prototype.toString()")}}
-
Nesnenin değerine bağlı olarak "true" ya da "false" dizesini döndürür. {{Jsxref ("Object.prototype.toString ()")}} methodunu geçersiz kılar.
-
{{jsxref("Boolean.prototype.valueOf()")}}
-
{{Jsxref ("Boolean")}} nesnesinin temel değerini döndürür. {{Jsxref ("Object.prototype.valueOf ()")}} methodunu geçersiz kılar.
-
- -

Özellikler

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ÖzelliklerDurumAçıklama
{{SpecName('ES1')}}{{Spec2('ES1')}}İlk tanım. JavaScript 1.0'da uygulanmaktadır.
{{SpecName('ES5.1', '#sec-15.6.3.1', 'Boolean.prototype')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-boolean.prototype', 'Boolean.prototype')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-boolean.prototype', 'Boolean.prototype')}}{{Spec2('ESDraft')}} 
- -

Tarayıcı Uyumluluğu

- -
- - -

{{Compat("javascript.builtins.Boolean.prototype")}}

-
diff --git a/files/tr/web/javascript/reference/global_objects/map/prototype/index.html b/files/tr/web/javascript/reference/global_objects/map/prototype/index.html deleted file mode 100644 index 1124f3602e..0000000000 --- a/files/tr/web/javascript/reference/global_objects/map/prototype/index.html +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: Map.prototype -slug: Web/JavaScript/Reference/Global_Objects/Map/prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Map -translation_of_original: Web/JavaScript/Reference/Global_Objects/Map/prototype ---- -
{{JSRef}}
- -

Map.prototype özelliği {{jsxref("Map")}} kurucusunun prototipini temsil eder.

- -
{{js_property_attributes(0,0,0)}}
- -

Tanım

- -

{{jsxref("Map")}} örnekleri {{jsxref("Map.prototype")}}'den miras alınır. Tüm Map örneklerine özellikler veya yöntemler eklemek için yapıcının prototip nesnesini kullanabilirsiniz.

- -

Özellikleri

- -
-
Map.prototype.constructor
-
Bir örneğin prototipini oluşturan işlevi döndürür. Bu, varsayılan olarak {{jsxref("Map")}} işlevidir.
-
{{jsxref("Map.prototype.size")}}
-
Map nesnesindeki anahtar / değer çiftlerinin sayısını döndürür.
-
- -

Yöntemler

- -
-
{{jsxref("Map.prototype.clear()")}}
-
Tüm anahtar / değer çiftlerini Map objesinden siler.
-
{{jsxref("Map.delete", "Map.prototype.delete(key)")}}
-
Map nesnesindeki bir öge varsa ve kaldırılmışsa true öge yoksa false döndürür. Map.prototype.has(key) daha sonra false döndürür.
-
{{jsxref("Map.prototype.entries()")}}
-
Ekleme sırasındaki Map nesnesindeki her öge için [anahtar, değer] dizisini içeren yeni bir Iterator nesnesini döndürür.
-
{{jsxref("Map.forEach", "Map.prototype.forEach(callbackFn[, thisArg])")}}
-
Map nesnesindeki her anahtar - değer çifti için ekleme sırasına göre callbackFn ögesini bir kez çağırır.  thisArg parametresi forEach için sağlanmışsa, her geri çağırma için bu değer olarak kullanılacaktır.
-
{{jsxref("Map.get", "Map.prototype.get(key)")}}
-
key ile ilişkilendirilmiş değeri veya hiçbir şey yoksa undefined değerini döndürür.
-
{{jsxref("Map.has", "Map.prototype.has(key)")}}
-
Map nesnesindeki bir değerin key ile ilişkili olup olmadığını belirten bir boolean döndürür.
-
{{jsxref("Map.prototype.keys()")}}
-
Map nesnesindeki her bir ögenin anahtarlarını ekleme sırasına göre içeren yeni bir Iterator nesnesi döndürür.
-
{{jsxref("Map.set", "Map.prototype.set(key, value)")}}
-
Mapnesnesindeki key değerini ayarlar. Map nesnesini döndürür.
-
{{jsxref("Map.prototype.values()")}}
-
Map nesnesindeki her bir ögenin değerlerini ekleme sırasına göre içeren yeni bir  Iterator nesnesi döndürür.
-
{{jsxref("Map.@@iterator", "Map.prototype[@@iterator]()")}}
-
Ekleme sırasındaki Map nesnesindeki her bir öge için[anahtar, değer] dizisini içeren yeni bir Iterator nesnesini döndürür.
-
- -

Şartlar

- - - - - - - - - - - - - - - - - - - -
ŞartDurumAçıklama
{{SpecName('ES2015', '#sec-map.prototype', 'Map.prototype')}}{{Spec2('ES2015')}} -

İlk tanım

-
{{SpecName('ESDraft', '#sec-map.prototype', 'Map.prototype')}}{{Spec2('ESDraft')}} 
- -

Tarayıcı Uyumluluğu

- - - -

{{Compat("javascript.builtins.Map.prototype")}}

- -

Ayrıca Bakınız

- - diff --git a/files/tr/web/javascript/reference/operators/function_star_/index.html b/files/tr/web/javascript/reference/operators/function_star_/index.html new file mode 100644 index 0000000000..193e00f205 --- /dev/null +++ b/files/tr/web/javascript/reference/operators/function_star_/index.html @@ -0,0 +1,84 @@ +--- +title: function* expression +slug: Web/JavaScript/Reference/Operatörler/function* +translation_of: Web/JavaScript/Reference/Operators/function* +--- +
{{jsSidebar("Operators")}}
+ +

The function* keyword can be used to define a generator function inside an expression.

+ +
{{EmbedInteractiveExample("pages/js/expressions-functionasteriskexpression.html")}}
+ + + +

Syntax

+ +
function* [name]([param1[, param2[, ..., paramN]]]) {
+   statements
+}
+ +

Parametreler

+ +
+
name
+
The function name. Can be omitted, in which case the function is anonymous. The name is only local to the function body.
+
paramN
+
Argüman adıdır, bir fonksiyon maxiumum 255 argüman alır.
+
statements
+
Fonksiyon kodları.
+
+ +

Açıklama

+ +

A function* expression is very similar to and has almost the same syntax as a {{jsxref('Statements/function*', 'function* statement')}}. The main difference between a function* expression and a function* statement is the function name, which can be omitted in function* expressions to create anonymous generator functions. See also the chapter about functions for more information.

+ +

Örnekler

+ +

Aşağıdaki adlandırılmamış fonksiyondur ve gelen değer karesini verir.

+ +
var x = function*(y) {
+   yield y * y;
+};
+
+ +

Özellikler

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES2015', '#', 'function*')}}{{Spec2('ES2015')}}Initial definition.
{{SpecName('ESDraft', '#', 'function*')}}{{Spec2('ESDraft')}} 
+ +

Tarayıcı uyumluluğu

+ + + +

{{Compat("javascript.operators.function_star")}}

+ +

Bakabilirsiniz

+ + diff --git a/files/tr/web/javascript/reference/operators/index.html b/files/tr/web/javascript/reference/operators/index.html new file mode 100644 index 0000000000..f42305b092 --- /dev/null +++ b/files/tr/web/javascript/reference/operators/index.html @@ -0,0 +1,277 @@ +--- +title: İfadeler ve operatörler +slug: Web/JavaScript/Reference/Operatörler +translation_of: Web/JavaScript/Reference/Operators +--- +
{{jsSidebar("Operators")}}
+ +

Bu döküman bütün JavaScript ifadelerini,operatörlerini ve anahtar kelimeleri içerir.

+ +

Expressions and operators by category

+ +

For an alphabetical listing see the sidebar on the left.

+ +

Birincil İfadeler

+ +

Genel İfadeler ve basit anahtar kelimeler.

+ +
+
{{jsxref("Operators/this", "this")}}
+
The this keyword refers to the function's execution context.
+
{{jsxref("Operators/function", "function")}}
+
The function keyword defines a function expression.
+
{{experimental_inline}} {{jsxref("Operators/class", "class")}}
+
The class keyword defines a class expression.
+
{{experimental_inline}} {{jsxref("Operators/function*", "function*")}}
+
The function* keyword defines a generator function expression.
+
{{experimental_inline}} {{jsxref("Operators/yield", "yield")}}
+
Pause and resume a generator function
+
{{experimental_inline}} {{jsxref("Operators/yield*", "yield*")}}
+
Delegate to another generator function or iterable object.
+
{{jsxref("Global_Objects/Array", "[]")}}
+
Array initializer/literal syntax.
+
{{jsxref("Operators/Object_initializer", "{}")}}
+
Object initializer/literal syntax.
+
{{jsxref("Global_Objects/RegExp", "/ab+c/i")}}
+
Regular expression literal syntax.
+
{{experimental_inline}} {{jsxref("Operators/Array_comprehensions", "[for (x of y) x]")}}
+
Array comprehensions.
+
{{experimental_inline}} {{jsxref("Operators/Generator_comprehensions", "(for (x of y) y)")}}
+
Generator comprehensions.
+
{{jsxref("Operators/Grouping", "( )")}}
+
Grouping operator.
+
+ +

Left-hand-side expressions

+ +

Left values are the destination of an assignment.

+ +
+
{{jsxref("Operators/Property_accessors", "Property accessors", "", 1)}}
+
Member operators provide access to a property or method of an object
+ (object.property and object["property"]).
+
{{jsxref("Operators/new", "new")}}
+
The new operator creates an instance of a constructor.
+
{{experimental_inline}} {{jsxref("Operators/super", "super")}}
+
The super keyword calls the parent constructor.
+
{{experimental_inline}} {{jsxref("Operators/Spread_operator", "...obj")}}
+
The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.
+
+ +

Increment and decrement

+ +

Postfix/prefix increment and postfix/prefix decrement operators.

+ +
+
{{jsxref("Operators/Arithmetic_Operators", "A++", "#Increment")}}
+
Postfix increment operator.
+
{{jsxref("Operators/Arithmetic_Operators", "A--", "#Decrement")}}
+
Postfix decrement operator.
+
{{jsxref("Operators/Arithmetic_Operators", "++A", "#Increment")}}
+
Prefix increment operator.
+
{{jsxref("Operators/Arithmetic_Operators", "--A", "#Decrement")}}
+
Prefix decrement operator.
+
+ +

Unary operators

+ +

A unary operation is operation with only one operand.

+ +
+
{{jsxref("Operators/delete", "delete")}}
+
The delete operator deletes a property from an object.
+
{{jsxref("Operators/void", "void")}}
+
The void operator discards an expression's return value.
+
{{jsxref("Operators/typeof", "typeof")}}
+
The typeof operator determines the type of a given object.
+
{{jsxref("Operators/Arithmetic_Operators", "+", "#Unary_plus")}}
+
The unary plus operator converts its operand to Number type.
+
{{jsxref("Operators/Arithmetic_Operators", "-", "#Unary_negation")}}
+
The unary negation operator converts its operand to Number type and then negates it.
+
{{jsxref("Operators/Bitwise_Operators", "~", "#Bitwise_NOT")}}
+
Bitwise NOT operator.
+
{{jsxref("Operators/Logical_Operators", "!", "#Logical_NOT")}}
+
Logical NOT operator.
+
+ +

Arithmetic operators

+ +

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.

+ +
+
{{jsxref("Operators/Arithmetic_Operators", "+", "#Addition")}}
+
Addition operator.
+
{{jsxref("Operators/Arithmetic_Operators", "-", "#Subtraction")}}
+
Subtraction operator.
+
{{jsxref("Operators/Arithmetic_Operators", "/", "#Division")}}
+
Division operator.
+
{{jsxref("Operators/Arithmetic_Operators", "*", "#Multiplication")}}
+
Multiplication operator.
+
{{jsxref("Operators/Arithmetic_Operators", "%", "#Remainder")}}
+
Remainder operator.
+
+ +

Relational operators

+ +

A comparison operator compares its operands and returns a Boolean value based on whether the comparison is true.

+ +
+
{{jsxref("Operators/in", "in")}}
+
The in operator determines whether an object has a given property.
+
{{jsxref("Operators/instanceof", "instanceof")}}
+
The instanceof operator determines whether an object is an instance of another object.
+
{{jsxref("Operators/Comparison_Operators", "<", "#Less_than_operator")}}
+
Less than operator.
+
{{jsxref("Operators/Comparison_Operators", ">", "#Greater_than_operator")}}
+
Greater than operator.
+
{{jsxref("Operators/Comparison_Operators", "<=", "#Less_than_or_equal_operator")}}
+
Less than or equal operator.
+
{{jsxref("Operators/Comparison_Operators", ">=", "#Greater_than_or_equal_operator")}}
+
Greater than or equal operator.
+
+ +

Equality operators

+ +

The result of evaluating an equality operator is always of type Boolean based on whether the comparison is true.

+ +
+
{{jsxref("Operators/Comparison_Operators", "==", "#Equality")}}
+
Equality operator.
+
{{jsxref("Operators/Comparison_Operators", "!=", "#Inequality")}}
+
Inequality operator.
+
{{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}
+
Identity operator.
+
{{jsxref("Operators/Comparison_Operators", "!==", "#Nonidentity")}}
+
Nonidentity operator.
+
+ +

Bitwise shift operators

+ +

Operations to shift all bits of the operand.

+ +
+
{{jsxref("Operators/Bitwise_Operators", "<<", "#Left_shift")}}
+
Bitwise left shift operator.
+
{{jsxref("Operators/Bitwise_Operators", ">>", "#Right_shift")}}
+
Bitwise right shift operator.
+
{{jsxref("Operators/Bitwise_Operators", ">>>", "#Unsigned_right_shift")}}
+
Bitwise unsigned right shift operator.
+
+ +

Binary bitwise operators

+ +

Bitwise operators treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values.

+ +
+
{{jsxref("Operators/Bitwise_Operators", "&", "#Bitwise_AND")}}
+
Bitwise AND.
+
{{jsxref("Operators/Bitwise_Operators", "|", "#Bitwise_OR")}}
+
Bitwise OR.
+
{{jsxref("Operators/Bitwise_Operators", "^", "#Bitwise_XOR")}}
+
Bitwise XOR.
+
+ +

Binary logical operators

+ +

Logical operators are typically used with boolean (logical) values, and when they are, they return a boolean value.

+ +
+
{{jsxref("Operators/Logical_Operators", "&&", "#Logical_AND")}}
+
Logical AND.
+
{{jsxref("Operators/Logical_Operators", "||", "#Logical_OR")}}
+
Logical OR.
+
+ +

Conditional (ternary) operator

+ +
+
{{jsxref("Operators/Conditional_Operator", "(condition ? ifTrue : ifFalse)")}}
+
+

The conditional operator returns one of two values based on the logical value of the condition.

+
+
+ +

Assignment operators

+ +

An assignment operator assigns a value to its left operand based on the value of its right operand.

+ +
+
{{jsxref("Operators/Assignment_Operators", "=", "#Assignment")}}
+
Assignment operator.
+
{{jsxref("Operators/Assignment_Operators", "*=", "#Multiplication_assignment")}}
+
Multiplication assignment.
+
{{jsxref("Operators/Assignment_Operators", "/=", "#Division_assignment")}}
+
Division assignment.
+
{{jsxref("Operators/Assignment_Operators", "%=", "#Remainder_assignment")}}
+
Remainder assignment.
+
{{jsxref("Operators/Assignment_Operators", "+=", "#Addition_assignment")}}
+
Addition assignment.
+
{{jsxref("Operators/Assignment_Operators", "-=", "#Subtraction_assignment")}}
+
Subtraction assignment
+
{{jsxref("Operators/Assignment_Operators", "<<=", "#Left_shift_assignment")}}
+
Left shift assignment.
+
{{jsxref("Operators/Assignment_Operators", ">>=", "#Right_shift_assignment")}}
+
Right shift assignment.
+
{{jsxref("Operators/Assignment_Operators", ">>>=", "#Unsigned_right_shift_assignment")}}
+
Unsigned right shift assignment.
+
{{jsxref("Operators/Assignment_Operators", "&=", "#Bitwise_AND_assignment")}}
+
Bitwise AND assignment.
+
{{jsxref("Operators/Assignment_Operators", "^=", "#Bitwise_XOR_assignment")}}
+
Bitwise XOR assignment.
+
{{jsxref("Operators/Assignment_Operators", "|=", "#Bitwise_OR_assignment")}}
+
Bitwise OR assignment.
+
{{experimental_inline}} {{jsxref("Operators/Destructuring_assignment", "[a, b] = [1, 2]")}}
+ {{experimental_inline}} {{jsxref("Operators/Destructuring_assignment", "{a, b} = {a:1, b:2}")}}
+
+

Destructuring assignment allows you to assign the properties of an array or object to variables using syntax that looks similar to array or object literals.

+
+
+ +

Comma operator

+ +
+
{{jsxref("Operators/Comma_Operator", ",")}}
+
The comma operator allows multiple expressions to be evaluated in a single statement and returns the result of the last expression.
+
+ +

Non-standard features

+ +
+
{{non-standard_inline}} {{jsxref("Operators/Legacy_generator_function", "Legacy generator function", "", 1)}}
+
The function keyword can be used to define a legacy generator function inside an expression. To make the function a legacy generator, the function body should contains at least one {{jsxref("Operators/yield", "yield")}} expression.
+
{{non-standard_inline}} {{jsxref("Operators/Expression_closures", "Expression closures", "", 1)}}
+
The expression closure syntax is a shorthand for writing simple function.
+
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
ECMAScript 1st Edition.StandardInitial definition.
{{SpecName('ES5.1', '#sec-11', 'Expressions')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-ecmascript-language-expressions', 'ECMAScript Language: Expressions')}}{{Spec2('ES6')}}New: Spread operator, destructuring assignment, super keyword, Array comprehensions, Generator comprehensions
+ +

See also

+ + diff --git a/files/tr/web/javascript/reference/operators/instanceof/index.html b/files/tr/web/javascript/reference/operators/instanceof/index.html new file mode 100644 index 0000000000..3434ea34b9 --- /dev/null +++ b/files/tr/web/javascript/reference/operators/instanceof/index.html @@ -0,0 +1,207 @@ +--- +title: instanceof +slug: Web/JavaScript/Reference/Operatörler/instanceof +translation_of: Web/JavaScript/Reference/Operators/instanceof +--- +
{{jsSidebar("Operators")}}
+ +

Instanceof operatorü bir nesne'nin prototip (prototype) zincirinin, belirli bir prototipin kurucu(constructor) metodu olup olmadığını testeder.

+ +

Syntax

+ +
object instanceof constructor
+ +

Parametreler

+ +
+
object
+
Test edilecek nesne
+
+ +
+
constructor
+
Test edilecek karşı kurucu fonksiyon
+
+ +

Açıklama

+ +

Instanceof operatorü nesnenin prototip zincirinde 'constructor.prototype' varlığını testeder.

+ +
// defining constructors
+function C() {}
+function D() {}
+
+var o = new C();
+
+// true, because: Object.getPrototypeOf(o) === C.prototype
+o instanceof C;
+
+// false, because D.prototype is nowhere in o's prototype chain
+o instanceof D;
+
+o instanceof Object; // true, because:
+C.prototype instanceof Object // true
+
+C.prototype = {};
+var o2 = new C();
+
+o2 instanceof C; // true
+
+// false, because C.prototype is nowhere in
+// o's prototype chain anymore
+o instanceof C;
+
+D.prototype = new C(); // add C to [[Prototype]] linkage of D
+var o3 = new D();
+o3 instanceof D; // true
+o3 instanceof C; // true since C.prototype is now in o3's prototype chain
+
+ +

Bir instanceof testinin değerinin yapıcıların prototip özelliklerinde yapılan değişikliklere göre değişebileceğini ve Object.setPrototypeOf kullanılarak bir nesne prototipini değiştirerek de değişebileceğini unutmayın. Standart olmayan __proto__ sözde-özelliği(pseudo-property) kullanarak da mümkündür.

+ +

instanceof ve çoklu bağlam (multiple context) (e.g. frames or windows)

+ +

Farklı kapsamların (Scopes) farklı yürütme (execution) ortamları vardır. Bu, farklı yerleşik yapılara sahip oldukları anlamına gelir (farklı global nesne, farklı yapıcılar, vb.). Bu, beklenmedik sonuçlara neden olabilir. Örneğin, [] instanceof window.frames [0] .Array false döndürür, çünkü Array.prototype! == window.frames [0] .Array ve diziler belli bir dizgeden (former) miras alırlar. Bu başlangıçta mantıklı gelmeyebilir, ancak betiğinizde (script) birden çok cerceve (frame) veya pencereyi (window) ele almaya başladığınızda ve nesneleri fonsiyonlarla bir bağlamdan diğerine geçirirken, bu geçerli ve güçlü bir sayı olacaktır. Örneğin, belirli bir nesnenin aslında Array.isArray (myObj) kullanarak bir Array olup olmadığını güvenli bir şekilde kontrol edebilirsiniz.

+ +
Mozilla geliştiricleri için not: + +

Kodda XPCOM kullanımının özel bir etkisi vardır: obj instanceof xpcomInterface (ör. Components.interfaces.nsIFile), obj.QueryInterface (xpcomInterface) çağırır ve QueryInterface başarılı olursa true değerini döndürür. Bu tür bir aramanın bir yan etkisi, başarılı bir örnekleme sonucunda obj'de xpcomInterface özelliklerini kullanabilmenizdir. Standart JavaScript globals'ın aksine, test obj instance of xpcomInterface, obj farklı bir kapsamdan olsa bile beklendiği gibi çalışır.

+
+ +

Examples

+ +

Demonstrating that String and Date are of type Object and exceptional cases

+ +

The following code uses instanceof to demonstrate that String and Date objects are also of type Object (they are derived from Object).

+ +

However, objects created with the object literal notation are an exception here: Although the prototype is undefined, instanceof Object returns true.

+ +
var simpleStr = 'This is a simple string';
+var myString  = new String();
+var newStr    = new String('String created with constructor');
+var myDate    = new Date();
+var myObj     = {};
+
+simpleStr instanceof String; // returns false, checks the prototype chain, finds undefined
+myString  instanceof String; // returns true
+newStr    instanceof String; // returns true
+myString  instanceof Object; // returns true
+
+myObj instanceof Object;    // returns true, despite an undefined prototype
+({})  instanceof Object;    // returns true, same case as above
+
+myString instanceof Date;   // returns false
+
+myDate instanceof Date;     // returns true
+myDate instanceof Object;   // returns true
+myDate instanceof String;   // returns false
+
+ +

Demonstrating that mycar is of type Car and type Object

+ +

The following code creates an object type Car and an instance of that object type, mycar. The instanceof operator demonstrates that the mycar object is of type Car and of type Object.

+ +
function Car(make, model, year) {
+  this.make = make;
+  this.model = model;
+  this.year = year;
+}
+var mycar = new Car('Honda', 'Accord', 1998);
+var a = mycar instanceof Car;    // returns true
+var b = mycar instanceof Object; // returns true
+
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ESDraft', '#sec-relational-operators', 'Relational Operators')}}{{Spec2('ESDraft')}} 
{{SpecName('ES6', '#sec-relational-operators', 'Relational Operators')}}{{Spec2('ES6')}} 
{{SpecName('ES5.1', '#sec-11.8.6', 'The instanceof operator')}}{{Spec2('ES5.1')}} 
{{SpecName('ES3', '#sec-11.8.6', 'The instanceof operator')}}{{Spec2('ES3')}}Initial definition. Implemented in JavaScript 1.4.
+ +

Browser compatibility

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

See also

+ + diff --git a/files/tr/web/javascript/reference/operators/super/index.html b/files/tr/web/javascript/reference/operators/super/index.html new file mode 100644 index 0000000000..3dd3f62ebf --- /dev/null +++ b/files/tr/web/javascript/reference/operators/super/index.html @@ -0,0 +1,165 @@ +--- +title: super +slug: Web/JavaScript/Reference/Operatörler/super +translation_of: Web/JavaScript/Reference/Operators/super +--- +
{{jsSidebar("Operators")}}
+ +

super, ebeveyn sınıftaki fonksiyonlara ulaşmak ve onları çağırmak için kullanılan bir ifadedir.

+ +

The super.prop and super[expr] expressions are valid in any method definition in both classes and object literals.

+ +

Sözdizimi (Syntax)

+ +
super([arguments]); // ebeveyn sınıfın constructot'ını çağırır.
+super.functionOnParent([arguments]); // ebeveyn sınıftaki functionOnParent fonksiyonunu çalıştırır.
+
+ +

Açıklama

+ +

Constructor içinde super ifadesi tek başına kullanılır ve this ifadesinden önce kullanılması zorunludur. Aynı zamanda super ifadesi ebeveyn sınıftaki fonksiyonları çağırmak için de kullanılabilir.

+ +

Örnekler

+ +

Sınflarda super kullanımı

+ +

This code snippet is taken from the classes sample (live demo). Here super() is called to avoid duplicating the constructor parts' that are common between Rectangle and Square.

+ +
class Rectangle {
+  constructor(height, width) {
+    this.name = 'Rectangle';
+    this.height = height;
+    this.width = width;
+  }
+  sayName() {
+    console.log('Hi, I am a ', this.name + '.');
+  }
+  get area() {
+    return this.height * this.width;
+  }
+  set area(value) {
+    this._area = value;
+  }
+}
+
+class Square extends Rectangle {
+  constructor(length) {
+    this.height; // ReferenceError, super needs to be called first!
+
+    // Here, it calls the parent class's constructor with lengths
+    // provided for the Rectangle's width and height
+    super(length, length);
+
+    // Note: In derived classes, super() must be called before you
+    // can use 'this'. Leaving this out will cause a reference error.
+    this.name = 'Square';
+  }
+}
+ +

Super-calling static methods

+ +

You are also able to call super on static methods.

+ +
class Rectangle {
+  static logNbSides() {
+    return 'I have 4 sides';
+  }
+}
+
+class Square extends Rectangle {
+  static logDescription() {
+    return super.logNbSides() + ' which are all equal';
+  }
+}
+Square.logDescription(); // 'I have 4 sides which are all equal'
+
+ +

Deleting super properties will throw an error

+ +

You cannot use the delete operator and super.prop or super[expr] to delete a parent class' property, it will throw a {{jsxref("ReferenceError")}}.

+ +
class Base {
+  foo() {}
+}
+class Derived extends Base {
+  delete() {
+    delete super.foo; // this is bad
+  }
+}
+
+new Derived().delete(); // ReferenceError: invalid delete involving 'super'. 
+ +

super.prop cannot overwrite non-writable properties

+ +

When defining non-writable properties with e.g. {{jsxref("Object.defineProperty")}}, super cannot overwrite the value of the property.

+ +
class X {
+  constructor() {
+    Object.defineProperty(this, 'prop', {
+      configurable: true,
+      writable: false,
+      value: 1
+    });
+  }
+}
+
+class Y extends X {
+  constructor() {
+    super();
+  }
+  foo() {
+    super.prop = 2;   // Cannot overwrite the value.
+  }
+}
+
+var y = new Y();
+y.foo(); // TypeError: "prop" is read-only
+console.log(y.prop); // 1
+
+ +

Using super.prop in object literals

+ +

Super can also be used in the object initializer / literal notation. In this example, two objects define a method. In the second object, super calls the first object's method. This works with the help of {{jsxref("Object.setPrototypeOf()")}} with which we are able to set the prototype of obj2 to obj1, so that super is able to find method1 on obj1.

+ +
var obj1 = {
+  method1() {
+    console.log('method 1');
+  }
+}
+
+var obj2 = {
+  method2() {
+    super.method1();
+  }
+}
+
+Object.setPrototypeOf(obj2, obj1);
+obj2.method2(); // logs "method 1"
+
+ +

Özellikler

+ + + + + + + + + + + + +
Specification
{{SpecName('ESDraft', '#sec-super-keyword', 'super')}}
+ +

Tarayıcı uyumluluğu

+ + + +

{{Compat("javascript.operators.super")}}

+ +

Ayrıca bakınız

+ + diff --git a/files/tr/web/javascript/reference/operators/this/index.html b/files/tr/web/javascript/reference/operators/this/index.html new file mode 100644 index 0000000000..674e577187 --- /dev/null +++ b/files/tr/web/javascript/reference/operators/this/index.html @@ -0,0 +1,347 @@ +--- +title: this +slug: Web/JavaScript/Reference/Operatörler/this +translation_of: Web/JavaScript/Reference/Operators/this +--- +
{{jsSidebar("Operators")}}
+ +

Fonksiyon'un this anahtar kelimesi diğer dillere göre birazcık farklı davranır. Ayrıca strict modu ve non-strict modu arasında farklılıklar bulunur.

+ +

Çoğunlukla, this'in değeri fonksiyonun çağrılma biçimine göre belirlenir. Çalışma esnasında değeri değiştirilemez, ve her fonksiyonu çağırışta farklı olabilir. ES5 bu adreste bind method to set the value of a function's this regardless of how it's called.

+ +

Sözdizimi

+ +
this
+ +

Global içerik

+ +

Global konumda (fonksiyon dışında), this global nesnesini referans gösterir, strict modunda olmak bu durumu değiştirmez..

+ +
console.log(this.document === document); // true
+
+// Web browserlerinde window objesi global objedir.:
+console.log(this === window); // true
+
+this.a = 37;
+console.log(window.a); // 37
+
+ +

Function içerik

+ +

Fonksiyon içerisinde, this'in değeri fonksiyonun nasıl çağrıldığına bağlıdır..

+ +

Basit çağrı

+ +
function f1(){
+  return this;
+}
+
+f1() === window; // global obje
+
+ +

Bu durumda, this'in değeri çağrı ile ayarlanmaz. Kod strict modda olmadığı sürece, this'in değeri mutlaka obje olmalıdır bu yüzdende default değer olan global objesi döner.

+ +
function f2(){
+  "use strict"; // strict modu içerisinde çalıştıralım
+  return this;
+}
+
+f2() === undefined;
+
+ +

Strict modu içerisinde, this'in değeri çalıştırılma içeriğine nasıl girdiyse o şekilde kalır. Eğer tanımlanmamışsa, undefined olarak kalır. Ayrıca tüm değerlere eşitlenebilir, örneğin null yada 42 yada "I am not this".

+ +
Not: İkinci örnekte, this undefined olmalıdır, çünkü f2 taban belirtilmeden çağrılmıştır. (örn: window.f2()). Bu özellik bazı browserlerde desteklenmemektedir. strict mod henüz geliştirme aşamasındayken çoğu browser yanlış davranarak window objesini döndürür.
+ +

Obje methodu cağrısı

+ +

Fonksiyon bir objenin methodu olarak çağrıldığında, this çağrıldığı obje olarak atanacaktır.

+ +

In the following example, when o.f() is invoked, inside the function this is bound to the o object.

+ +
var o = {
+  prop: 37,
+  f: function() {
+    return this.prop;
+  }
+};
+
+console.log(o.f()); // logs 37
+
+ +

Note that this behavior is not at all affected by how or where the function was defined. In the previous example, we defined the function inline as the f member during the definition of o. However, we could have just as easily defined the function first and later attached it to o.f. Doing so results in the same behavior:

+ +
var o = {prop: 37};
+
+function independent() {
+  return this.prop;
+}
+
+o.f = independent;
+
+console.log(o.f()); // logs 37
+
+ +

This demonstrates that it matters only that the function was invoked from the f member of o.

+ +

Similarly, the this binding is only affected by the most immediate member reference. In the following example, when we invoke the function, we call it as a method g of the object o.b. This time during execution, this inside the function will refer to o.b. The fact that the object is itself a member of o has no consequence; the most immediate reference is all that matters.

+ +
o.b = {g: independent, prop: 42};
+console.log(o.b.g()); // logs 42
+
+ +

this on the object's prototype chain

+ +

The same notion holds true for methods defined somewhere on the object's prototype chain. If the method is on an object's prototype chain, this refers to the object the method was called on, as if the method was on the object.

+ +
var o = {f:function(){ return this.a + this.b; }};
+var p = Object.create(o);
+p.a = 1;
+p.b = 4;
+
+console.log(p.f()); // 5
+
+ +

In this example, the object assigned to the variable p doesn't have its own f property, it inherits it from its prototype. But it doesn't matter that the lookup for f eventually finds a member with that name on o; the lookup began as a reference to p.f, so this inside the function takes the value of the object referred to as p. That is, since f is called as a method of p, its this refers to p. This is an interesting feature of JavaScript's prototype inheritance.

+ +

this with a getter or setter

+ +

Again, the same notion holds true when a function is invoked from a getter or a setter. A function used as getter or setter has its this bound to the object from which the property is being set or gotten.

+ +
function modulus(){
+  return Math.sqrt(this.re * this.re + this.im * this.im);
+}
+
+var o = {
+  re: 1,
+  im: -1,
+  get phase(){
+    return Math.atan2(this.im, this.re);
+  }
+};
+
+Object.defineProperty(o, 'modulus', {
+    get: modulus, enumerable:true, configurable:true});
+
+console.log(o.phase, o.modulus); // logs -0.78 1.4142
+
+ +

As a constructor

+ +

When a function is used as a constructor (with the new keyword), its this is bound to the new object being constructed.

+ +

Note: while the default for a constructor is to return the object referenced by this, it can instead return some other object (if the return value isn't an object, then the this object is returned).

+ +
/*
+ * Constructors work like this:
+ *
+ * function MyConstructor(){
+ *   // Actual function body code goes here.
+ *   // Create properties on |this| as
+ *   // desired by assigning to them.  E.g.,
+ *   this.fum = "nom";
+ *   // et cetera...
+ *
+ *   // If the function has a return statement that
+ *   // returns an object, that object will be the
+ *   // result of the |new| expression.  Otherwise,
+ *   // the result of the expression is the object
+ *   // currently bound to |this|
+ *   // (i.e., the common case most usually seen).
+ * }
+ */
+
+function C(){
+  this.a = 37;
+}
+
+var o = new C();
+console.log(o.a); // logs 37
+
+
+function C2(){
+  this.a = 37;
+  return {a:38};
+}
+
+o = new C2();
+console.log(o.a); // logs 38
+
+ +

In the last example (C2), because an object was returned during construction, the new object that this was bound to simply gets discarded. (This essentially makes the statement "this.a = 37;" dead code. It's not exactly dead, because it gets executed, but it can be eliminated with no outside effects.)

+ +

call and apply

+ +

Where a function uses the this keyword in its body, its value can be bound to a particular object in the call using the call or apply methods that all functions inherit from Function.prototype.

+ +
function add(c, d){
+  return this.a + this.b + c + d;
+}
+
+var o = {a:1, b:3};
+
+// The first parameter is the object to use as
+// 'this', subsequent parameters are passed as
+// arguments in the function call
+add.call(o, 5, 7); // 1 + 3 + 5 + 7 = 16
+
+// The first parameter is the object to use as
+// 'this', the second is an array whose
+// members are used as the arguments in the function call
+add.apply(o, [10, 20]); // 1 + 3 + 10 + 20 = 34
+
+ +

Note that with call and apply, if the value passed as this is not an object, an attempt will be made to convert it to an object using the internal ToObject operation. So if the value passed is a primitive like 7 or 'foo', it will be converted to an Object using the related constructor, so the primitive number 7 is converted to an object as if by new Number(7) and the string 'foo' to an object as if by new String('foo'), e.g.

+ +
function bar() {
+  console.log(Object.prototype.toString.call(this));
+}
+
+bar.call(7); // [object Number]
+
+ +

The bind method

+ +

ECMAScript 5 introduced Function.prototype.bind. Calling f.bind(someObject) creates a new function with the same body and scope as f, but where this occurs in the original function, in the new function it is permanently bound to the first argument of bind, regardless of how the function is being used.

+ +
function f(){
+  return this.a;
+}
+
+var g = f.bind({a:"azerty"});
+console.log(g()); // azerty
+
+var o = {a:37, f:f, g:g};
+console.log(o.f(), o.g()); // 37, azerty
+
+ +

As a DOM event handler

+ +

When a function is used as an event handler, its this is set to the element the event fired from (some browsers do not follow this convention for listeners added dynamically with methods other than addEventListener).

+ +
// When called as a listener, turns the related element blue
+function bluify(e){
+  // Always true
+  console.log(this === e.currentTarget);
+  // true when currentTarget and target are the same object
+  console.log(this === e.target);
+  this.style.backgroundColor = '#A5D9F3';
+}
+
+// Get a list of every element in the document
+var elements = document.getElementsByTagName('*');
+
+// Add bluify as a click listener so when the
+// element is clicked on, it turns blue
+for(var i=0 ; i<elements.length ; i++){
+  elements[i].addEventListener('click', bluify, false);
+}
+ +

In an in–line event handler

+ +

When code is called from an in–line handler, its this is set to the DOM element on which the listener is placed:

+ +
<button onclick="alert(this.tagName.toLowerCase());">
+  Show this
+</button>
+
+ +

The above alert shows button. Note however that only the outer code has its this set this way:

+ +
<button onclick="alert((function(){return this}()));">
+  Show inner this
+</button>
+
+ +

In this case, the inner function's this isn't set so it returns the global/window object (i.e. the default object in non–strict mode where this isn't set by the call).

+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-this-keyword', 'The this keyword')}}{{Spec2('ES6')}} 
{{SpecName('ES5.1', '#sec-11.1.1', 'The this keyword')}}{{Spec2('ES5.1')}} 
{{SpecName('ES3', '#sec-11.1.1', 'The this keyword')}}{{Spec2('ES3')}} 
{{SpecName('ES1', '#sec-11.1.1', 'The this keyword')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.0.
+ +

Browser compatibility

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

See also

+ + diff --git a/files/tr/web/javascript/reference/operators/typeof/index.html b/files/tr/web/javascript/reference/operators/typeof/index.html new file mode 100644 index 0000000000..deccfd8925 --- /dev/null +++ b/files/tr/web/javascript/reference/operators/typeof/index.html @@ -0,0 +1,259 @@ +--- +title: typeof +slug: Web/JavaScript/Reference/Operatörler/typeof +translation_of: Web/JavaScript/Reference/Operators/typeof +--- +
{{jsSidebar("Operatörler")}}
+ +

Typeof operatörü, değerlendirilmemiş işlenenin türünü gösteren bir dize döndürür.

+ +
{{EmbedInteractiveExample("pages/js/expressions-typeof.html")}}
+ + + +

Sözdizimi

+ +

The typeof operator is followed by its operand:

+ +
typeof operand
+or
+typeof (operand)
+
+ + + +

Parametreler

+ +

operand is an expression representing the object or {{Glossary("Primitive", "primitive")}} whose type is to be returned.

+ +

Parantez isteğe bağlıdır.

+ +

Description

+ +

The following table summarizes the possible return values of typeof. For more information about types and primitives, see also the JavaScript data structure page.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeResult
Undefined"undefined"
Null"object" (see below)
Boolean"boolean"
Number"number"
String"string"
Symbol (new in ECMAScript 2015)"symbol"
Host object (provided by the JS environment)Implementation-dependent
Function object (implements [[Call]] in ECMA-262 terms)"function"
Any other object"object"
+ +

Örnekler

+ +
// Sayılar
+typeof 37 === 'number';
+typeof 3.14 === 'number';
+typeof(42) === 'number';
+typeof Math.LN2 === 'number';
+typeof Infinity === 'number';
+typeof NaN === 'number'; // Despite being "Not-A-Number"
+typeof Number(1) === 'number'; // but never use this form!
+
+
+// Metinler
+typeof '' === 'string';
+typeof 'bla' === 'string';
+typeof '1' === 'string'; // note that a number within a string is still typeof string
+typeof (typeof 1) === 'string'; // typeof always returns a string
+typeof String('abc') === 'string'; // but never use this form!
+
+
+// Booleans
+typeof true === 'boolean';
+typeof false === 'boolean';
+typeof Boolean(true) === 'boolean'; // but never use this form!
+
+
+// Symbols
+typeof Symbol() === 'symbol'
+typeof Symbol('foo') === 'symbol'
+typeof Symbol.iterator === 'symbol'
+
+
+// Undefined
+typeof undefined === 'undefined';
+typeof declaredButUndefinedVariable === 'undefined';
+typeof undeclaredVariable === 'undefined';
+
+
+// Objeler
+typeof {a: 1} === 'object';
+
+// use Array.isArray or Object.prototype.toString.call
+// to differentiate regular objects from arrays
+typeof [1, 2, 4] === 'object';
+
+typeof new Date() === 'object';
+
+
+// The following is confusing. Don't use!
+typeof new Boolean(true) === 'object';
+typeof new Number(1) === 'object';
+typeof new String('abc') === 'object';
+
+
+// Fonksiyonlar
+typeof function() {} === 'function';
+typeof class C {} === 'function';
+typeof Math.sin === 'function';
+
+ +

null

+ +
// This stands since the beginning of JavaScript
+typeof null === 'object';
+
+ +

In the first implementation of JavaScript, JavaScript values were represented as a type tag and a value. The type tag for objects was 0. null was represented as the NULL pointer (0x00 in most platforms). Consequently, null had 0 as type tag, hence the bogus typeof return value. (reference)

+ +

A fix was proposed for ECMAScript (via an opt-in), but was rejected. It would have resulted in typeof null === 'null'.

+ +

new operatör kullanımı

+ +
// All constructor functions while instantiated with 'new' keyword will always be typeof 'object'
+var str = new String('String');
+var num = new Number(100);
+
+typeof str; // It will return 'object'
+typeof num; // It will return 'object'
+
+// But there is a exception in case of Function constructor of Javascript
+
+var func = new Function();
+
+typeof func; // It will return 'function'
+
+ +

Parantezlere ihtiyaç var

+ +
// Parentheses will be very much useful to determine the data type for expressions.
+var iData = 99;
+
+typeof iData + ' Wisen'; // It will return 'number Wisen'
+typeof (iData + ' Wisen'); // It will return 'string'
+
+
+
+ +

Düzenli İfadeler

+ +

Callable regular expressions were a non-standard addition in some browsers.

+ +
typeof /s/ === 'function'; // Chrome 1-12 Non-conform to ECMAScript 5.1
+typeof /s/ === 'object';   // Firefox 5+  Conform to ECMAScript 5.1
+
+ +

Temporal Dead Zone errors

+ +

Before ECMAScript 2015, typeof was always guaranteed to return a string for any operand it was supplied with. But with the addition of non-hoisted, block-scoped let and const, using typeof on let and const variables in a block before they are declared will throw a ReferenceError. This is in contrast with undeclared variables, for which typeof will return 'undefined'. Block scoped variables are in a "temporal dead zone" from the start of the block until the initialization is processed, during which, it will throw an error if accessed.

+ +
typeof undeclaredVariable === 'undefined';
+typeof newLetVariable; let newLetVariable; // ReferenceError
+typeof newConstVariable; const newConstVariable = 'hello'; // ReferenceError
+
+ +

İstisnalar

+ +

All current browsers expose a non-standard host object {{domxref("document.all")}} with type Undefined.

+ +
typeof document.all === 'undefined';
+
+ +

Although the specification allows custom type tags for non-standard exotic objects, it requires those type tags to be different from the predefined ones. The case of document.all having type tag 'undefined' must be classified as an exceptional violation of the rules.

+ +

Özellikler

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ESDraft', '#sec-typeof-operator', 'The typeof Operator')}}{{Spec2('ESDraft')}}
{{SpecName('ES6', '#sec-typeof-operator', 'The typeof Operator')}}{{Spec2('ES6')}}
{{SpecName('ES5.1', '#sec-11.4.3', 'The typeof Operator')}}{{Spec2('ES5.1')}}
{{SpecName('ES3', '#sec-11.4.3', 'The typeof Operator')}}{{Spec2('ES3')}}
{{SpecName('ES1', '#sec-11.4.3', 'The typeof Operator')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.1.
+ +

Browser compatibility

+ + + +

{{Compat("javascript.operators.typeof")}}

+ +

IE özel notlar

+ +

On IE 6, 7, and 8 a lot of host objects are objects and not functions. For example:

+ +
typeof alert === 'object'
+ +

Bakabilirsiniz

+ + diff --git "a/files/tr/web/javascript/reference/operat\303\266rler/arithmetic_operators/index.html" "b/files/tr/web/javascript/reference/operat\303\266rler/arithmetic_operators/index.html" deleted file mode 100644 index 04d337601d..0000000000 --- "a/files/tr/web/javascript/reference/operat\303\266rler/arithmetic_operators/index.html" +++ /dev/null @@ -1,294 +0,0 @@ ---- -title: Arithmetic operators -slug: Web/JavaScript/Reference/Operatörler/Arithmetic_Operators -tags: - - Aritmetik Operatörler - - JavaScript -translation_of: Web/JavaScript/Reference/Operators -translation_of_original: Web/JavaScript/Reference/Operators/Arithmetic_Operators ---- -
{{jsSidebar("Operators")}}
- -

Aritmetik operatörler sayısal değerleri (değişmez değerler veya değişkenler) kendi değişkeni olarak alır ve tek bir sayısal değer döndürür. Standart aritmetik operatörler toplama (+), çıkarma (-), çıkarma (*), ve bölme (/).

- -
{{EmbedInteractiveExample("pages/js/expressions-arithmetic.html")}}
- - - -

Toplama (+)

- -

Toplama işleci, sayısal değişkenlerin veya dize birleşiminin toplamını üretir.

- -

Syntax

- -
Operator: x + y
-
- -

Examples

- -
// Number + Number -> Toplama
-1 + 2 // 3
-
-// Boolean + Number -> Toplama
-true + 1 // 2
-
-// Boolean + Boolean -> Toplama
-false + false // 0
-
-// Number + String -> Birleşim
-5 + 'foo' // "5foo"
-
-// String + Boolean -> Birleşim
-'foo' + false // "foofalse"
-
-// String + String -> Birleşim
-'foo' + 'bar' // "foobar"
-
- -

Çıkarma (-)

- -

Çıkarma işleci (operator), iki değişkeni çıkarır ve farklarını üretir.

- -

Söz Dizimi

- -
Operator: x - y
-
- -

Örnekler

- -
5 - 3 // 2
-3 - 5 // -2
-'foo' - 3 // NaN(Sayı Değil)
- -

Bölme (/)

- -

Bölme operatörü, sol değişkenin bölüm olduğu ve sağ değişkenin bölen olduğu işlenenlerin bölümünü üretir.

- -

Söz Dizimi

- -
Operator: x / y
-
- -

Örnekler

- -
1 / 2      // 0.5 döndürür
-1 / 2      // Java''da 0 döndürür
-// (her iki sayı da açıkça kayan nokta sayısıdır)
-
-1.0 / 2.0  // JavaScript ve Java 0.5 döndürür
-
-2.0 / 0    // JavaScript sonsuz döndürür
-2.0 / 0.0  // Sonsuzu da döndürür
-2.0 / -0.0 // JavaScript eksi sonsuz da döndürür
- -

Çarpma (*)

- -

Çarpma operatörü değişkenlerin ürününü üretir.

- -

Söz Dizimi

- -
Operator: x * y
-
- -

Örnekler

- -
2 * 2 // 4
--2 * 2 // -4
-Infinity * 0 // NaN(Sayı Değil1)
-Infinity * Infinity // Sonsuz
-'foo' * 2 // NaN
-
- -

Kalan (%)

- -

Kalan operatörü, bir değişken ikinci bir değişken tarafından bölündüğünde kalan döndürür. Her zaman bölüm işareti alır.

- -

Söz Dizimi

- -
Operator: var1 % var2
-
- -

Örnekler

- -
12 % 5 // 2
--1 % 2 // -1
-1 % -2 // 1
-NaN % 2 // NaN
-1 % 2 // 1
-2 % 3 // 2
--4 % 2 // -0
-5.5 % 2 // 1.5
-
- -

Üs (**)

- -

The exponentiation operator returns the result of raising first operand to the power second operand. That is, var1var2, in the preceding statement, where var1 and var2 are variables. Exponentiation operator is right associative. a ** b ** c is equal to a ** (b ** c).

- -

Syntax

- -
Operator: var1 ** var2
-
- -

Notes

- -

In most languages like PHP and Python and others that have an exponentiation operator (**), the exponentiation operator is defined to have a higher precedence than unary operators such as unary + and unary -, but there are a few exceptions. For example, in Bash the ** operator is defined to have a lower precedence than unary operators. In JavaScript, it is impossible to write an ambiguous exponentiation expression, i.e. you cannot put a unary operator (+/-/~/!/delete/void/typeof) immediately before the base number.

- -
-2 ** 2;
-// 4 in Bash, -4 in other languages.
-// This is invalid in JavaScript, as the operation is ambiguous.
-
-
--(2 ** 2);
-// -4 in JavaScript and the author's intention is unambiguous.
-
- -

Examples

- -
2 ** 3 // 8
-3 ** 2 // 9
-3 ** 2.5 // 15.588457268119896
-10 ** -1 // 0.1
-NaN ** 2 // NaN
-
-2 ** 3 ** 2 // 512
-2 ** (3 ** 2) // 512
-(2 ** 3) ** 2 // 64
-
- -

To invert the sign of the result of an exponentiation expression:

- -
-(2 ** 2) // -4
-
- -

To force the base of an exponentiation expression to be a negative number:

- -
(-2) ** 2 // 4
-
- -
-

Note: JavaScript also has a bitwise operator ^ (logical XOR). ** and ^ are different (for example : 2 ** 3 === 8 when 2 ^ 3 === 1.)

-
- -

Artırma (++)

- -

Artış operatörü işlenenini artırır (bir ekler) ve bir değer döndürür.

- - - -

Söz Dizimi

- -
Operator: x++ yada ++x
-
- -

Örnekler

- -
// Postfix
-var x = 3;
-y = x++; // y = 3, x = 4
-
-// Prefix
-var a = 2;
-b = ++a; // a = 3, b = 3
-
- -

Azaltma (--)

- -

The decrement operator decrements (subtracts one from) its operand and returns a value.

- - - -

Syntax

- -
Operator: x-- or --x
-
- -

Examples

- -
// Postfix
-var x = 3;
-y = x--; // y = 3, x = 2
-
-// Prefix
-var a = 2;
-b = --a; // a = 1, b = 1
-
- -

Unary negation (-)

- -

The unary negation operator precedes its operand and negates it.

- -

Syntax

- -
Operator: -x
-
- -

Examples

- -
var x = 3;
-y = -x; // y = -3, x = 3
-
-// Unary negation operator can convert non-numbers into a number
-var x = "4";
-y = -x; // y = -4
-
- -

Unary plus (+)

- -

The unary plus operator precedes its operand and evaluates to its operand but attempts to convert it into a number, if it isn't already. Although unary negation (-) also can convert non-numbers, unary plus is the fastest and preferred way of converting something into a number, because it does not perform any other operations on the number. It can convert string representations of integers and floats, as well as the non-string values true, false, and null. Integers in both decimal and hexadecimal ("0x"-prefixed) formats are supported. Negative numbers are supported (though not for hex). If it cannot parse a particular value, it will evaluate to {{jsxref("NaN")}}.

- -

Syntax

- -
Operator: +x
-
- -

Examples

- -
+3     // 3
-+'3'   // 3
-+true  // 1
-+false // 0
-+null  // 0
-+function(val){ return val } // NaN
-
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - -
Specification
{{SpecName('ESDraft', '#sec-additive-operators', 'Additive operators')}}
{{SpecName('ESDraft', '#sec-postfix-expressions', 'Postfix expressions')}}
{{SpecName('ESDraft', '#sec-11.5', 'Multiplicative operators')}}
{{SpecName('ESDraft', '#sec-11.4', 'Unary operator')}}
- -

Browser compatibility

- - - -

{{Compat("javascript.operators.arithmetic")}}

- -

See also

- - diff --git "a/files/tr/web/javascript/reference/operat\303\266rler/bitwise_operators/index.html" "b/files/tr/web/javascript/reference/operat\303\266rler/bitwise_operators/index.html" deleted file mode 100644 index 410107226b..0000000000 --- "a/files/tr/web/javascript/reference/operat\303\266rler/bitwise_operators/index.html" +++ /dev/null @@ -1,565 +0,0 @@ ---- -title: Bitwise operators -slug: Web/JavaScript/Reference/Operatörler/Bitwise_Operators -translation_of: Web/JavaScript/Reference/Operators -translation_of_original: Web/JavaScript/Reference/Operators/Bitwise_Operators ---- -
{{jsSidebar("Operators")}}
- -

Bitsel işleçler işlediği elemanlara ondalık, onaltılık veya sayılar yerine 32 bit diziler(sıfır ve birler) olarak davranır. Örneğin, onluk bir sayı olan 9, ikilik sistemde 1001 ile gösterilir. Bitsel işleçler, işlemin iki tarafınada ikili değerleriyle işlem yapar ancak JavaScript standartı olan sayısal değerleri döner.

- -

Aşağıdaki tablo JavaScript'in bitsel işleçlerini özetler:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OperatorUsageDescription
Bitwise ANDa & bBitsel işleçin iki tarafının karşılık gelen bitleri 1 ise, en az bir tanesi 0 ise 0 döndürür.
Bitwise ORa | bBitsel işleçin iki tarafının karşılık gelen bitlerinden en az biri 1 ise 1 döndürür.
Bitwise XORa ^ bBitsel işleçin iki tarafının karşılık gelen bitlerinden ancak bir tanesi 1 ise, 1 döndürür.
Bitwise NOT~ aİşlenenin bitlerini ters çevirir.
Left shifta << ba sayısının ikili haline, sağına b (< 32) adet bit 0 ekleyerek sola doğru kaydırır.
Sign-propagating right shifta >> ba sayısının ikili halini b (< 32) adet bit sağa kaydırır. Pozitif sayılar için b adet 0, negatif sayılar için 1 ekleyerek kaydırır.
Zero-fill right shifta >>> ba sayısının ikili gösterimine b (< 32) bit sağa kaydırır, a sayısının pozitif negatif olmasına bakmadan sayının soluna b adet 0 ekler.
- -

İşaretli 32-bit integer sayılar

- -

The operands of all bitwise operators are converted to signed 32-bit integers in two's complement format. Two's complement format means that a number's negative counterpart (e.g. 5 vs. -5) is all the number's bits inverted (bitwise NOT of the number, a.k.a. ones' complement of the number) plus one. For example, the following encodes the integer 314:

- -
00000000000000000000000100111010
-
- -

The following encodes ~314, i.e. the ones' complement of -314:

- -
11111111111111111111111011000101
-
- -

Finally, the following encodes -314, i.e. the two's complement of -314:

- -
11111111111111111111111011000110
-
- -

The two's complement guarantees that the left-most bit is 0 when the number is positive and 1 when the number is negative. Thus, it is called the sign bit.

- -

The number 0 is the integer that is composed completely of 0 bits.

- -
0 (base 10) = 00000000000000000000000000000000 (base 2)
-
- -

The number -1 is the integer that is composed completely of 1 bits.

- -
-1 (base 10) = 11111111111111111111111111111111 (base 2)
-
- -

The number -2147483648 (hexadecimal representation: -0x80000000) is the integer that is composed completely of 0 bits except the first (left-most) one.

- -
-2147483648 (base 10) = 10000000000000000000000000000000 (base 2)
-
- -

The number 2147483647 (hexadecimal representation: 0x7fffffff) is the integer that is composed completely of 1 bits except the first (left-most) one.

- -
2147483647 (base 10) = 01111111111111111111111111111111 (base 2)
-
- -

The numbers -2147483648 and 2147483647 are the minimum and the maximum integers representable through a 32bit signed number.

- -

Bitwise logical operators

- -

Conceptually, the bitwise logical operators work as follows:

- - - -

& (Bitwise AND)

- -

Performs the AND operation on each pair of bits. a AND b yields 1 only if both a and b are 1. The truth table for the AND operation is:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
aba AND b
000
010
100
111
- -
.    9 (base 10) = 00000000000000000000000000001001 (base 2)
-    14 (base 10) = 00000000000000000000000000001110 (base 2)
-                   --------------------------------
-14 & 9 (base 10) = 00000000000000000000000000001000 (base 2) = 8 (base 10)
-
- -

Bitwise ANDing any number x with 0 yields 0. Bitwise ANDing any number x with -1 yields x.

- -

| (Bitwise OR)

- -

Performs the OR operation on each pair of bits. a OR b yields 1 if either a or b is 1. The truth table for the OR operation is:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
aba OR b
000
011
101
111
- -
.    9 (base 10) = 00000000000000000000000000001001 (base 2)
-    14 (base 10) = 00000000000000000000000000001110 (base 2)
-                   --------------------------------
-14 | 9 (base 10) = 00000000000000000000000000001111 (base 2) = 15 (base 10)
-
- -

Bitwise ORing any number x with 0 yields x. Bitwise ORing any number x with -1 yields -1.

- -

^ (Bitwise XOR)

- -

Performs the XOR operation on each pair of bits. a XOR b yields 1 if a and b are different. The truth table for the XOR operation is:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
aba XOR b
000
011
101
110
- -
.    9 (base 10) = 00000000000000000000000000001001 (base 2)
-    14 (base 10) = 00000000000000000000000000001110 (base 2)
-                   --------------------------------
-14 ^ 9 (base 10) = 00000000000000000000000000000111 (base 2) = 7 (base 10)
-
- -

Bitwise XORing any number x with 0 yields x. Bitwise XORing any number x with -1 yields ~x.

- -

~ (Bitwise NOT)

- -

Performs the NOT operator on each bit. NOT a yields the inverted value (a.k.a. one's complement) of a. The truth table for the NOT operation is:

- - - - - - - - - - - - - - - - -
aNOT a
01
10
- -
 9 (base 10) = 00000000000000000000000000001001 (base 2)
-               --------------------------------
-~9 (base 10) = 11111111111111111111111111110110 (base 2) = -10 (base 10)
-
- -

Bitwise NOTing any number x yields -(x + 1). For example, ~-5 yields 4.

- -

Example with indexOf:

- -
var str = 'rawr';
-var searchFor = 'a';
-
-// this is alternative way of typing if (-1*str.indexOf('a') <= 0)
-if (~str.indexOf(searchFor)) {
-  // searchFor is in the string
-} else {
-  // searchFor is not in the string
-}
-
-// here are the values returned by (~str.indexOf(searchFor))
-// r == -1
-// a == -2
-// w == -3
-
- -

Bitwise shift operators

- -

The bitwise shift operators take two operands: the first is a quantity to be shifted, and the second specifies the number of bit positions by which the first operand is to be shifted. The direction of the shift operation is controlled by the operator used.

- -

Shift operators convert their operands to 32-bit integers in big-endian order and return a result of the same type as the left operand. The right operand should be less than 32, but if not only the low five bits will be used.

- -

<< (Left shift)

- -

This operator shifts the first operand the specified number of bits to the left. Excess bits shifted off to the left are discarded. Zero bits are shifted in from the right.

- -

For example, 9 << 2 yields 36:

- -
.    9 (base 10): 00000000000000000000000000001001 (base 2)
-                  --------------------------------
-9 << 2 (base 10): 00000000000000000000000000100100 (base 2) = 36 (base 10)
-
- -

Bitwise shifting any number x to the left by y bits yields x * 2^y.

- -

>> (Sign-propagating right shift)

- -

This operator shifts the first operand the specified number of bits to the right. Excess bits shifted off to the right are discarded. Copies of the leftmost bit are shifted in from the left. Since the new leftmost bit has the same value as the previous leftmost bit, the sign bit (the leftmost bit) does not change. Hence the name "sign-propagating".

- -

For example, 9 >> 2 yields 2:

- -
.    9 (base 10): 00000000000000000000000000001001 (base 2)
-                  --------------------------------
-9 >> 2 (base 10): 00000000000000000000000000000010 (base 2) = 2 (base 10)
-
- -

Likewise, -9 >> 2 yields -3, because the sign is preserved:

- -
.    -9 (base 10): 11111111111111111111111111110111 (base 2)
-                   --------------------------------
--9 >> 2 (base 10): 11111111111111111111111111111101 (base 2) = -3 (base 10)
-
- -

>>> (Zero-fill right shift)

- -

This operator shifts the first operand the specified number of bits to the right. Excess bits shifted off to the right are discarded. Zero bits are shifted in from the left. The sign bit becomes 0, so the result is always non-negative.

- -

For non-negative numbers, zero-fill right shift and sign-propagating right shift yield the same result. For example, 9 >>> 2 yields 2, the same as 9 >> 2:

- -
.     9 (base 10): 00000000000000000000000000001001 (base 2)
-                   --------------------------------
-9 >>> 2 (base 10): 00000000000000000000000000000010 (base 2) = 2 (base 10)
-
- -

However, this is not the case for negative numbers. For example, -9 >>> 2 yields 1073741821, which is different than -9 >> 2 (which yields -3):

- -
.     -9 (base 10): 11111111111111111111111111110111 (base 2)
-                    --------------------------------
--9 >>> 2 (base 10): 00111111111111111111111111111101 (base 2) = 1073741821 (base 10)
-
- -

Examples

- -

Flags and bitmasks

- -

The bitwise logical operators are often used to create, manipulate, and read sequences of flags, which are like binary variables. Variables could be used instead of these sequences, but binary flags take much less memory (by a factor of 32).

- -

Suppose there are 4 flags:

- - - -

These flags are represented by a sequence of bits: DCBA. When a flag is set, it has a value of 1. When a flag is cleared, it has a value of 0. Suppose a variable flags has the binary value 0101:

- -
var flags = 5;   // binary 0101
-
- -

This value indicates:

- - - -

Since bitwise operators are 32-bit, 0101 is actually 00000000000000000000000000000101, but the preceding zeroes can be neglected since they contain no meaningful information.

- -

A bitmask is a sequence of bits that can manipulate and/or read flags. Typically, a "primitive" bitmask for each flag is defined:

- -
var FLAG_A = 1; // 0001
-var FLAG_B = 2; // 0010
-var FLAG_C = 4; // 0100
-var FLAG_D = 8; // 1000
-
- -

New bitmasks can be created by using the bitwise logical operators on these primitive bitmasks. For example, the bitmask 1011 can be created by ORing FLAG_A, FLAG_B, and FLAG_D:

- -
var mask = FLAG_A | FLAG_B | FLAG_D; // 0001 | 0010 | 1000 => 1011
-
- -

Individual flag values can be extracted by ANDing them with a bitmask, where each bit with the value of one will "extract" the corresponding flag. The bitmask masks out the non-relevant flags by ANDing with zeroes (hence the term "bitmask"). For example, the bitmask 0100 can be used to see if flag C is set:

- -
// if we own a cat
-if (flags & FLAG_C) { // 0101 & 0100 => 0100 => true
-   // do stuff
-}
-
- -

A bitmask with multiple set flags acts like an "either/or". For example, the following two are equivalent:

- -
// if we own a bat or we own a cat
-// (0101 & 0010) || (0101 & 0100) => 0000 || 0100 => true
-if ((flags & FLAG_B) || (flags & FLAG_C)) {
-   // do stuff
-}
-
- -
// if we own a bat or cat
-var mask = FLAG_B | FLAG_C; // 0010 | 0100 => 0110
-if (flags & mask) { // 0101 & 0110 => 0100 => true
-   // do stuff
-}
-
- -

Flags can be set by ORing them with a bitmask, where each bit with the value one will set the corresponding flag, if that flag isn't already set. For example, the bitmask 1100 can be used to set flags C and D:

- -
// yes, we own a cat and a duck
-var mask = FLAG_C | FLAG_D; // 0100 | 1000 => 1100
-flags |= mask;   // 0101 | 1100 => 1101
-
- -

Flags can be cleared by ANDing them with a bitmask, where each bit with the value zero will clear the corresponding flag, if it isn't already cleared. This bitmask can be created by NOTing primitive bitmasks. For example, the bitmask 1010 can be used to clear flags A and C:

- -
// no, we don't have an ant problem or own a cat
-var mask = ~(FLAG_A | FLAG_C); // ~0101 => 1010
-flags &= mask;   // 1101 & 1010 => 1000
-
- -

The mask could also have been created with ~FLAG_A & ~FLAG_C (De Morgan's law):

- -
// no, we don't have an ant problem, and we don't own a cat
-var mask = ~FLAG_A & ~FLAG_C;
-flags &= mask;   // 1101 & 1010 => 1000
-
- -

Flags can be toggled by XORing them with a bitmask, where each bit with the value one will toggle the corresponding flag. For example, the bitmask 0110 can be used to toggle flags B and C:

- -
// if we didn't have a bat, we have one now,
-// and if we did have one, bye-bye bat
-// same thing for cats
-var mask = FLAG_B | FLAG_C;
-flags = flags ^ mask;   // 1100 ^ 0110 => 1010
-
- -

Finally, the flags can all be flipped with the NOT operator:

- -
// entering parallel universe...
-flags = ~flags;    // ~1010 => 0101
-
- -

Conversion snippets

- -

Convert a binary String to a decimal Number:

- -
var sBinString = '1011';
-var nMyNumber = parseInt(sBinString, 2);
-alert(nMyNumber); // prints 11, i.e. 1011
-
- -

Convert a decimal Number to a binary String:

- -
var nMyNumber = 11;
-var sBinString = nMyNumber.toString(2);
-alert(sBinString); // prints 1011, i.e. 11
-
- -

Automate Mask Creation

- -

You can create multiple masks from a set of Boolean values, like this:

- -
function createMask() {
-  var nMask = 0, nFlag = 0, nLen = arguments.length > 32 ? 32 : arguments.length;
-  for (nFlag; nFlag < nLen; nMask |= arguments[nFlag] << nFlag++);
-  return nMask;
-}
-var mask1 = createMask(true, true, false, true); // 11, i.e.: 1011
-var mask2 = createMask(false, false, true); // 4, i.e.: 0100
-var mask3 = createMask(true); // 1, i.e.: 0001
-// etc.
-
-alert(mask1); // prints 11, i.e.: 1011
-
- -

Reverse algorithm: an array of booleans from a mask

- -

If you want to create an Array of Booleans from a mask you can use this code:

- -
function arrayFromMask(nMask) {
-  // nMask must be between -2147483648 and 2147483647
-  if (nMask > 0x7fffffff || nMask < -0x80000000) {
-    throw new TypeError('arrayFromMask - out of range');
-  }
-  for (var nShifted = nMask, aFromMask = []; nShifted;
-       aFromMask.push(Boolean(nShifted & 1)), nShifted >>>= 1);
-  return aFromMask;
-}
-
-var array1 = arrayFromMask(11);
-var array2 = arrayFromMask(4);
-var array3 = arrayFromMask(1);
-
-alert('[' + array1.join(', ') + ']');
-// prints "[true, true, false, true]", i.e.: 11, i.e.: 1011
-
- -

You can test both algorithms at the same time…

- -
var nTest = 19; // our custom mask
-var nResult = createMask.apply(this, arrayFromMask(nTest));
-
-alert(nResult); // 19
-
- -

For didactic purpose only (since there is the Number.toString(2) method), we show how it is possible to modify the arrayFromMask algorithm in order to create a String containing the binary representation of a Number, rather than an Array of Booleans:

- -
function createBinaryString(nMask) {
-  // nMask must be between -2147483648 and 2147483647
-  for (var nFlag = 0, nShifted = nMask, sMask = ''; nFlag < 32;
-       nFlag++, sMask += String(nShifted >>> 31), nShifted <<= 1);
-  return sMask;
-}
-
-var string1 = createBinaryString(11);
-var string2 = createBinaryString(4);
-var string3 = createBinaryString(1);
-
-alert(string1);
-// prints 00000000000000000000000000001011, i.e. 11
-
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition.
{{SpecName('ES5.1', '#sec-11.7')}}{{Spec2('ES5.1')}}Defined in several sections of the specification: Bitwise NOT operator, Bitwise shift operators, Binary bitwise operators
{{SpecName('ES6', '#sec-bitwise-shift-operators')}}{{Spec2('ES6')}}Defined in several sections of the specification: Bitwise NOT operator, Bitwise shift operators, Binary bitwise operators
{{SpecName('ESDraft', '#sec-bitwise-shift-operators')}}{{Spec2('ESDraft')}}Defined in several sections of the specification: Bitwise NOT operator, Bitwise shift operators, Binary bitwise operators
- -

Browser compatibility

- - - -

{{Compat("javascript.operators.bitwise")}}

- -

See also

- - diff --git "a/files/tr/web/javascript/reference/operat\303\266rler/function_star_/index.html" "b/files/tr/web/javascript/reference/operat\303\266rler/function_star_/index.html" deleted file mode 100644 index 193e00f205..0000000000 --- "a/files/tr/web/javascript/reference/operat\303\266rler/function_star_/index.html" +++ /dev/null @@ -1,84 +0,0 @@ ---- -title: function* expression -slug: Web/JavaScript/Reference/Operatörler/function* -translation_of: Web/JavaScript/Reference/Operators/function* ---- -
{{jsSidebar("Operators")}}
- -

The function* keyword can be used to define a generator function inside an expression.

- -
{{EmbedInteractiveExample("pages/js/expressions-functionasteriskexpression.html")}}
- - - -

Syntax

- -
function* [name]([param1[, param2[, ..., paramN]]]) {
-   statements
-}
- -

Parametreler

- -
-
name
-
The function name. Can be omitted, in which case the function is anonymous. The name is only local to the function body.
-
paramN
-
Argüman adıdır, bir fonksiyon maxiumum 255 argüman alır.
-
statements
-
Fonksiyon kodları.
-
- -

Açıklama

- -

A function* expression is very similar to and has almost the same syntax as a {{jsxref('Statements/function*', 'function* statement')}}. The main difference between a function* expression and a function* statement is the function name, which can be omitted in function* expressions to create anonymous generator functions. See also the chapter about functions for more information.

- -

Örnekler

- -

Aşağıdaki adlandırılmamış fonksiyondur ve gelen değer karesini verir.

- -
var x = function*(y) {
-   yield y * y;
-};
-
- -

Özellikler

- - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES2015', '#', 'function*')}}{{Spec2('ES2015')}}Initial definition.
{{SpecName('ESDraft', '#', 'function*')}}{{Spec2('ESDraft')}} 
- -

Tarayıcı uyumluluğu

- - - -

{{Compat("javascript.operators.function_star")}}

- -

Bakabilirsiniz

- - diff --git "a/files/tr/web/javascript/reference/operat\303\266rler/index.html" "b/files/tr/web/javascript/reference/operat\303\266rler/index.html" deleted file mode 100644 index f42305b092..0000000000 --- "a/files/tr/web/javascript/reference/operat\303\266rler/index.html" +++ /dev/null @@ -1,277 +0,0 @@ ---- -title: İfadeler ve operatörler -slug: Web/JavaScript/Reference/Operatörler -translation_of: Web/JavaScript/Reference/Operators ---- -
{{jsSidebar("Operators")}}
- -

Bu döküman bütün JavaScript ifadelerini,operatörlerini ve anahtar kelimeleri içerir.

- -

Expressions and operators by category

- -

For an alphabetical listing see the sidebar on the left.

- -

Birincil İfadeler

- -

Genel İfadeler ve basit anahtar kelimeler.

- -
-
{{jsxref("Operators/this", "this")}}
-
The this keyword refers to the function's execution context.
-
{{jsxref("Operators/function", "function")}}
-
The function keyword defines a function expression.
-
{{experimental_inline}} {{jsxref("Operators/class", "class")}}
-
The class keyword defines a class expression.
-
{{experimental_inline}} {{jsxref("Operators/function*", "function*")}}
-
The function* keyword defines a generator function expression.
-
{{experimental_inline}} {{jsxref("Operators/yield", "yield")}}
-
Pause and resume a generator function
-
{{experimental_inline}} {{jsxref("Operators/yield*", "yield*")}}
-
Delegate to another generator function or iterable object.
-
{{jsxref("Global_Objects/Array", "[]")}}
-
Array initializer/literal syntax.
-
{{jsxref("Operators/Object_initializer", "{}")}}
-
Object initializer/literal syntax.
-
{{jsxref("Global_Objects/RegExp", "/ab+c/i")}}
-
Regular expression literal syntax.
-
{{experimental_inline}} {{jsxref("Operators/Array_comprehensions", "[for (x of y) x]")}}
-
Array comprehensions.
-
{{experimental_inline}} {{jsxref("Operators/Generator_comprehensions", "(for (x of y) y)")}}
-
Generator comprehensions.
-
{{jsxref("Operators/Grouping", "( )")}}
-
Grouping operator.
-
- -

Left-hand-side expressions

- -

Left values are the destination of an assignment.

- -
-
{{jsxref("Operators/Property_accessors", "Property accessors", "", 1)}}
-
Member operators provide access to a property or method of an object
- (object.property and object["property"]).
-
{{jsxref("Operators/new", "new")}}
-
The new operator creates an instance of a constructor.
-
{{experimental_inline}} {{jsxref("Operators/super", "super")}}
-
The super keyword calls the parent constructor.
-
{{experimental_inline}} {{jsxref("Operators/Spread_operator", "...obj")}}
-
The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.
-
- -

Increment and decrement

- -

Postfix/prefix increment and postfix/prefix decrement operators.

- -
-
{{jsxref("Operators/Arithmetic_Operators", "A++", "#Increment")}}
-
Postfix increment operator.
-
{{jsxref("Operators/Arithmetic_Operators", "A--", "#Decrement")}}
-
Postfix decrement operator.
-
{{jsxref("Operators/Arithmetic_Operators", "++A", "#Increment")}}
-
Prefix increment operator.
-
{{jsxref("Operators/Arithmetic_Operators", "--A", "#Decrement")}}
-
Prefix decrement operator.
-
- -

Unary operators

- -

A unary operation is operation with only one operand.

- -
-
{{jsxref("Operators/delete", "delete")}}
-
The delete operator deletes a property from an object.
-
{{jsxref("Operators/void", "void")}}
-
The void operator discards an expression's return value.
-
{{jsxref("Operators/typeof", "typeof")}}
-
The typeof operator determines the type of a given object.
-
{{jsxref("Operators/Arithmetic_Operators", "+", "#Unary_plus")}}
-
The unary plus operator converts its operand to Number type.
-
{{jsxref("Operators/Arithmetic_Operators", "-", "#Unary_negation")}}
-
The unary negation operator converts its operand to Number type and then negates it.
-
{{jsxref("Operators/Bitwise_Operators", "~", "#Bitwise_NOT")}}
-
Bitwise NOT operator.
-
{{jsxref("Operators/Logical_Operators", "!", "#Logical_NOT")}}
-
Logical NOT operator.
-
- -

Arithmetic operators

- -

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.

- -
-
{{jsxref("Operators/Arithmetic_Operators", "+", "#Addition")}}
-
Addition operator.
-
{{jsxref("Operators/Arithmetic_Operators", "-", "#Subtraction")}}
-
Subtraction operator.
-
{{jsxref("Operators/Arithmetic_Operators", "/", "#Division")}}
-
Division operator.
-
{{jsxref("Operators/Arithmetic_Operators", "*", "#Multiplication")}}
-
Multiplication operator.
-
{{jsxref("Operators/Arithmetic_Operators", "%", "#Remainder")}}
-
Remainder operator.
-
- -

Relational operators

- -

A comparison operator compares its operands and returns a Boolean value based on whether the comparison is true.

- -
-
{{jsxref("Operators/in", "in")}}
-
The in operator determines whether an object has a given property.
-
{{jsxref("Operators/instanceof", "instanceof")}}
-
The instanceof operator determines whether an object is an instance of another object.
-
{{jsxref("Operators/Comparison_Operators", "<", "#Less_than_operator")}}
-
Less than operator.
-
{{jsxref("Operators/Comparison_Operators", ">", "#Greater_than_operator")}}
-
Greater than operator.
-
{{jsxref("Operators/Comparison_Operators", "<=", "#Less_than_or_equal_operator")}}
-
Less than or equal operator.
-
{{jsxref("Operators/Comparison_Operators", ">=", "#Greater_than_or_equal_operator")}}
-
Greater than or equal operator.
-
- -

Equality operators

- -

The result of evaluating an equality operator is always of type Boolean based on whether the comparison is true.

- -
-
{{jsxref("Operators/Comparison_Operators", "==", "#Equality")}}
-
Equality operator.
-
{{jsxref("Operators/Comparison_Operators", "!=", "#Inequality")}}
-
Inequality operator.
-
{{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}
-
Identity operator.
-
{{jsxref("Operators/Comparison_Operators", "!==", "#Nonidentity")}}
-
Nonidentity operator.
-
- -

Bitwise shift operators

- -

Operations to shift all bits of the operand.

- -
-
{{jsxref("Operators/Bitwise_Operators", "<<", "#Left_shift")}}
-
Bitwise left shift operator.
-
{{jsxref("Operators/Bitwise_Operators", ">>", "#Right_shift")}}
-
Bitwise right shift operator.
-
{{jsxref("Operators/Bitwise_Operators", ">>>", "#Unsigned_right_shift")}}
-
Bitwise unsigned right shift operator.
-
- -

Binary bitwise operators

- -

Bitwise operators treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values.

- -
-
{{jsxref("Operators/Bitwise_Operators", "&", "#Bitwise_AND")}}
-
Bitwise AND.
-
{{jsxref("Operators/Bitwise_Operators", "|", "#Bitwise_OR")}}
-
Bitwise OR.
-
{{jsxref("Operators/Bitwise_Operators", "^", "#Bitwise_XOR")}}
-
Bitwise XOR.
-
- -

Binary logical operators

- -

Logical operators are typically used with boolean (logical) values, and when they are, they return a boolean value.

- -
-
{{jsxref("Operators/Logical_Operators", "&&", "#Logical_AND")}}
-
Logical AND.
-
{{jsxref("Operators/Logical_Operators", "||", "#Logical_OR")}}
-
Logical OR.
-
- -

Conditional (ternary) operator

- -
-
{{jsxref("Operators/Conditional_Operator", "(condition ? ifTrue : ifFalse)")}}
-
-

The conditional operator returns one of two values based on the logical value of the condition.

-
-
- -

Assignment operators

- -

An assignment operator assigns a value to its left operand based on the value of its right operand.

- -
-
{{jsxref("Operators/Assignment_Operators", "=", "#Assignment")}}
-
Assignment operator.
-
{{jsxref("Operators/Assignment_Operators", "*=", "#Multiplication_assignment")}}
-
Multiplication assignment.
-
{{jsxref("Operators/Assignment_Operators", "/=", "#Division_assignment")}}
-
Division assignment.
-
{{jsxref("Operators/Assignment_Operators", "%=", "#Remainder_assignment")}}
-
Remainder assignment.
-
{{jsxref("Operators/Assignment_Operators", "+=", "#Addition_assignment")}}
-
Addition assignment.
-
{{jsxref("Operators/Assignment_Operators", "-=", "#Subtraction_assignment")}}
-
Subtraction assignment
-
{{jsxref("Operators/Assignment_Operators", "<<=", "#Left_shift_assignment")}}
-
Left shift assignment.
-
{{jsxref("Operators/Assignment_Operators", ">>=", "#Right_shift_assignment")}}
-
Right shift assignment.
-
{{jsxref("Operators/Assignment_Operators", ">>>=", "#Unsigned_right_shift_assignment")}}
-
Unsigned right shift assignment.
-
{{jsxref("Operators/Assignment_Operators", "&=", "#Bitwise_AND_assignment")}}
-
Bitwise AND assignment.
-
{{jsxref("Operators/Assignment_Operators", "^=", "#Bitwise_XOR_assignment")}}
-
Bitwise XOR assignment.
-
{{jsxref("Operators/Assignment_Operators", "|=", "#Bitwise_OR_assignment")}}
-
Bitwise OR assignment.
-
{{experimental_inline}} {{jsxref("Operators/Destructuring_assignment", "[a, b] = [1, 2]")}}
- {{experimental_inline}} {{jsxref("Operators/Destructuring_assignment", "{a, b} = {a:1, b:2}")}}
-
-

Destructuring assignment allows you to assign the properties of an array or object to variables using syntax that looks similar to array or object literals.

-
-
- -

Comma operator

- -
-
{{jsxref("Operators/Comma_Operator", ",")}}
-
The comma operator allows multiple expressions to be evaluated in a single statement and returns the result of the last expression.
-
- -

Non-standard features

- -
-
{{non-standard_inline}} {{jsxref("Operators/Legacy_generator_function", "Legacy generator function", "", 1)}}
-
The function keyword can be used to define a legacy generator function inside an expression. To make the function a legacy generator, the function body should contains at least one {{jsxref("Operators/yield", "yield")}} expression.
-
{{non-standard_inline}} {{jsxref("Operators/Expression_closures", "Expression closures", "", 1)}}
-
The expression closure syntax is a shorthand for writing simple function.
-
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
ECMAScript 1st Edition.StandardInitial definition.
{{SpecName('ES5.1', '#sec-11', 'Expressions')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-ecmascript-language-expressions', 'ECMAScript Language: Expressions')}}{{Spec2('ES6')}}New: Spread operator, destructuring assignment, super keyword, Array comprehensions, Generator comprehensions
- -

See also

- - diff --git "a/files/tr/web/javascript/reference/operat\303\266rler/instanceof/index.html" "b/files/tr/web/javascript/reference/operat\303\266rler/instanceof/index.html" deleted file mode 100644 index 3434ea34b9..0000000000 --- "a/files/tr/web/javascript/reference/operat\303\266rler/instanceof/index.html" +++ /dev/null @@ -1,207 +0,0 @@ ---- -title: instanceof -slug: Web/JavaScript/Reference/Operatörler/instanceof -translation_of: Web/JavaScript/Reference/Operators/instanceof ---- -
{{jsSidebar("Operators")}}
- -

Instanceof operatorü bir nesne'nin prototip (prototype) zincirinin, belirli bir prototipin kurucu(constructor) metodu olup olmadığını testeder.

- -

Syntax

- -
object instanceof constructor
- -

Parametreler

- -
-
object
-
Test edilecek nesne
-
- -
-
constructor
-
Test edilecek karşı kurucu fonksiyon
-
- -

Açıklama

- -

Instanceof operatorü nesnenin prototip zincirinde 'constructor.prototype' varlığını testeder.

- -
// defining constructors
-function C() {}
-function D() {}
-
-var o = new C();
-
-// true, because: Object.getPrototypeOf(o) === C.prototype
-o instanceof C;
-
-// false, because D.prototype is nowhere in o's prototype chain
-o instanceof D;
-
-o instanceof Object; // true, because:
-C.prototype instanceof Object // true
-
-C.prototype = {};
-var o2 = new C();
-
-o2 instanceof C; // true
-
-// false, because C.prototype is nowhere in
-// o's prototype chain anymore
-o instanceof C;
-
-D.prototype = new C(); // add C to [[Prototype]] linkage of D
-var o3 = new D();
-o3 instanceof D; // true
-o3 instanceof C; // true since C.prototype is now in o3's prototype chain
-
- -

Bir instanceof testinin değerinin yapıcıların prototip özelliklerinde yapılan değişikliklere göre değişebileceğini ve Object.setPrototypeOf kullanılarak bir nesne prototipini değiştirerek de değişebileceğini unutmayın. Standart olmayan __proto__ sözde-özelliği(pseudo-property) kullanarak da mümkündür.

- -

instanceof ve çoklu bağlam (multiple context) (e.g. frames or windows)

- -

Farklı kapsamların (Scopes) farklı yürütme (execution) ortamları vardır. Bu, farklı yerleşik yapılara sahip oldukları anlamına gelir (farklı global nesne, farklı yapıcılar, vb.). Bu, beklenmedik sonuçlara neden olabilir. Örneğin, [] instanceof window.frames [0] .Array false döndürür, çünkü Array.prototype! == window.frames [0] .Array ve diziler belli bir dizgeden (former) miras alırlar. Bu başlangıçta mantıklı gelmeyebilir, ancak betiğinizde (script) birden çok cerceve (frame) veya pencereyi (window) ele almaya başladığınızda ve nesneleri fonsiyonlarla bir bağlamdan diğerine geçirirken, bu geçerli ve güçlü bir sayı olacaktır. Örneğin, belirli bir nesnenin aslında Array.isArray (myObj) kullanarak bir Array olup olmadığını güvenli bir şekilde kontrol edebilirsiniz.

- -
Mozilla geliştiricleri için not: - -

Kodda XPCOM kullanımının özel bir etkisi vardır: obj instanceof xpcomInterface (ör. Components.interfaces.nsIFile), obj.QueryInterface (xpcomInterface) çağırır ve QueryInterface başarılı olursa true değerini döndürür. Bu tür bir aramanın bir yan etkisi, başarılı bir örnekleme sonucunda obj'de xpcomInterface özelliklerini kullanabilmenizdir. Standart JavaScript globals'ın aksine, test obj instance of xpcomInterface, obj farklı bir kapsamdan olsa bile beklendiği gibi çalışır.

-
- -

Examples

- -

Demonstrating that String and Date are of type Object and exceptional cases

- -

The following code uses instanceof to demonstrate that String and Date objects are also of type Object (they are derived from Object).

- -

However, objects created with the object literal notation are an exception here: Although the prototype is undefined, instanceof Object returns true.

- -
var simpleStr = 'This is a simple string';
-var myString  = new String();
-var newStr    = new String('String created with constructor');
-var myDate    = new Date();
-var myObj     = {};
-
-simpleStr instanceof String; // returns false, checks the prototype chain, finds undefined
-myString  instanceof String; // returns true
-newStr    instanceof String; // returns true
-myString  instanceof Object; // returns true
-
-myObj instanceof Object;    // returns true, despite an undefined prototype
-({})  instanceof Object;    // returns true, same case as above
-
-myString instanceof Date;   // returns false
-
-myDate instanceof Date;     // returns true
-myDate instanceof Object;   // returns true
-myDate instanceof String;   // returns false
-
- -

Demonstrating that mycar is of type Car and type Object

- -

The following code creates an object type Car and an instance of that object type, mycar. The instanceof operator demonstrates that the mycar object is of type Car and of type Object.

- -
function Car(make, model, year) {
-  this.make = make;
-  this.model = model;
-  this.year = year;
-}
-var mycar = new Car('Honda', 'Accord', 1998);
-var a = mycar instanceof Car;    // returns true
-var b = mycar instanceof Object; // returns true
-
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ESDraft', '#sec-relational-operators', 'Relational Operators')}}{{Spec2('ESDraft')}} 
{{SpecName('ES6', '#sec-relational-operators', 'Relational Operators')}}{{Spec2('ES6')}} 
{{SpecName('ES5.1', '#sec-11.8.6', 'The instanceof operator')}}{{Spec2('ES5.1')}} 
{{SpecName('ES3', '#sec-11.8.6', 'The instanceof operator')}}{{Spec2('ES3')}}Initial definition. Implemented in JavaScript 1.4.
- -

Browser compatibility

- -

{{CompatibilityTable}}

- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

See also

- - diff --git "a/files/tr/web/javascript/reference/operat\303\266rler/mantiksal_operatorler/index.html" "b/files/tr/web/javascript/reference/operat\303\266rler/mantiksal_operatorler/index.html" deleted file mode 100644 index 8a1e2ea56f..0000000000 --- "a/files/tr/web/javascript/reference/operat\303\266rler/mantiksal_operatorler/index.html" +++ /dev/null @@ -1,312 +0,0 @@ ---- -title: Mantıksal Operatörler -slug: Web/JavaScript/Reference/Operatörler/Mantiksal_Operatorler -tags: - - Değil - - JavaScript - - Mantıksal Operatörler - - Operator - - Referans - - ve - - ya da -translation_of: Web/JavaScript/Reference/Operators -translation_of_original: Web/JavaScript/Reference/Operators/Logical_Operators ---- -
{{jsSidebar("Operators")}}
- -

Mantıksal operatörler genellikle {{jsxref("Boolean")}} (mantıksal) değerleri ile kullanılır. Kullanıldıklarında, bir boolean değer döndürürler. Ancak, && ve || operatörleri aslında belirtilmiş olan operandlardan birinin değerini döndürür, bu sebeple eğer bu operatörler Boolean olmayan değerler ile kullanılırsa, Boolean olmayan değerler üretebilirler.

- -

Açıklama

- -

Mantıksal operatörler aşağıdaki tabloda açıklanıyor:

- - - - - - - - - - - - - - - - - - - - - - - - -
OperatörKullanımAçıklama
Mantıksal VE (&&)expr1 && expr2Eğer expr1 false değerine dönüştürülebilirse, expr1  döndürülür. Aksi halde, expr2 döndürülür. Böylece, Boolean değerleri ile kullanıldıklarında, && her iki operand true ise true ; aksi halde, false döndürür.
Mantıksal YA DA (||)expr1 || expr2Eğer expr1 true değerine dönüştürülebilirse, expr1 döndürülür, aksi halde, expr2 döndürülür. Böylece, Boolean değerleri ile kullanıldıklarında, || her iki operanddan herhangi biri true ise true döndürür.
Mantıksal DEĞİL (!)!exprEğer operandın değeri true is false döndürür, aksi alde true döndürür.
- -

Eğer bir değer true değerine dönüştürülebiliyorsa, ona {{Glossary("truthy")}} ismi verilir. Eğer bir değer false değerine dönüştürülebiliyorsa, ona {{Glossary("falsy")}} denir.

- -

False değerine dönüştürülebilen ifadelere örnekler:

- - - -

&& ve || operatörleri Boolean olmayan değerler ile kullanılabiliyor olmasına rağmen, döndürdükleri değerler her zaman Boolean değerlerine çevirilebildiğinden, halen Boolean operatörleri olarak düşünülebilirler.

- -

Kısa-devre değerlendirmeleri

- -

Mantıksal operatörler soldan sağa çalıştırıldıkları gibi, mümkünse aşağıdaki kurallar kullanılarak "kısa devre" testine tabi tutulurlar:

- - - -

Mantık kuralları bu değerlendirmelerin doğruluğunu garantiler. Yukarıdaki ifadelerin tümünün çalıştırılmayacağına, bu sebeple hepsinin yan etkisinin olmayacağına dikkat edin. Ayrıca yukarıdaki ifadenin (herhangi) kısmının tamamıyla bir mantıksal ifadeye eşit olduğuna dikkat edin. (parantezler ile gösterildiği gibi).

- -

Örneğin, aşağıdaki iki fonksiyon birbirinin aynısıdır.

- -
function shortCircuitEvaluation() {
-  doSomething() || doSomethingElse()
-}
-
-function equivalentEvaluation() {
-  var flag = doSomething();
-  if (!flag) {
-    doSomethingElse();
-  }
-}
-
- -

Ancak, aşağıdaki ifadeler operatör önceliğine göre eşit değildir ve sağ el operatörünün tek bir ifade olmasının önemini vurgular (gerekirse parantezler ile gruplanır).

- -
false && true  || true      // returns true
-false && (true || true)     // returns false
- -

Mantıksal VE (&&)

- -

Aşağıdaki kod && (mantıksal VE) operatörüyle ilgili örnekleri gösterir.

- -
a1 = true  && true      // t && t returns true
-a2 = true  && false     // t && f returns false
-a3 = false && true      // f && t returns false
-a4 = false && (3 == 4)  // f && f returns false
-a5 = "Cat" && "Dog"     // t && t returns "Dog"
-a6 = false && "Cat"     // f && t returns false
-a7 = "Cat" && false     // t && f returns false
-a8 = "" && false        // returns ""
-a9 = false && ||        // returns false
-
- -

Mantıksal YA DA (||)

- -

Aşağıdaki kod || (mantıksal YA DA) operatörüyle ilgili örnekleri gösterir.

- -
o1 = true  || true       // t || t returns true
-o2 = false || true       // f || t returns true
-o3 = true  || false      // t || f returns true
-o4 = false || (3 == 4)   // f || f returns false
-o5 = "Cat" || "Dog"      // t || t returns "Cat"
-o6 = false || "Cat"      // f || t returns "Cat"
-o7 = "Cat" || false      // t || f returns "Cat"
-o8 = ""    || false      // returns false
-o9 = false || ""         // returns ""
-
- -

Mantıksal DEĞİL (!)

- -

Aşağıdaki kod ! (mantıksal DEĞİL) operatörüyle ilgili örnekleri gösterir.

- -
n1 = !true              // !t returns false
-n2 = !false             // !f returns true
-n3 = !"Cat"             // !t returns false
-
- -

Dönüşüm kuralları

- -

VE operatörünü YA DA operatörüne dönüştürmek

- -

Booleanları içeren aşağıdaki ifade:

- -
bCondition1 && bCondition2
- -

her zaman şuna eşittir:

- -
!(!bCondition1 || !bCondition2)
- -

YA DA operatörünü VE operatörüne çevirmek

- -

Booleanları içeren aşağıdaki ifade:

- -
bCondition1 || bCondition2
- -

her zaman şuna eşittir:

- -
!(!bCondition1 && !bCondition2)
- -

DEĞİL operatörleri arasında dönüşüm yapmak

- -

Booleanları içeren aşağıdaki ifade:

- -
!!bCondition
- -

her zaman şuna eşittir: 

- -
bCondition
- -

İç içe geçmiş parantezleri kaldırmak

- -

Mantıksal operatörlerin soldan sağa değerlendirilmesi durumunda, kompleks bir ifadeden parantezleri bazı kuralları takip ederek kaldırmak mümkündür.

- -

İç içe geçmiş VE operatörünü kaldırmak

- -

Aşağıda, Boolean içeren bu bileşik işlem:

- -
bCondition1 || (bCondition2 && bCondition3)
- -

her zaman şuna eşittir:

- -
bCondition1 || bCondition2 && bCondition3
- -

İç içe geçmiş YA DA operatörünü kaldırmak

- -

Aşağıda, Boolean içeren bu bileşik ifade:

- -
bCondition1 && (bCondition2 || bCondition3)
- -

her zaman şuna eşittir:

- -
!(!bCondition1 || !bCondition2 && !bCondition3)
- -

Özellikler

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ÖzellikDurumAçıklama
{{SpecName('ES1')}}{{Spec2('ES1')}}İlk tanım.
{{SpecName('ES5.1', '#sec-11.11')}}{{Spec2('ES5.1')}}Tarifnamenin birkaç bölümünde tanımlandı: Logical NOT Operator, Binary Logical Operators
{{SpecName('ES6', '#sec-binary-logical-operators')}}{{Spec2('ES6')}}Tarifnamenin birkaç bölümünde tanımlandı: Logical NOT Operator, Binary Logical Operators
{{SpecName('ESDraft', '#sec-binary-logical-operators')}}{{Spec2('ESDraft')}}Tarifnamenin birkaç bölümünde tanımlandı: Logical NOT Operator, Binary Logical Operators
- -

Tarayıcı Uyumluluğu

- -

{{CompatibilityTable}}

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Mantıksal VE (&&){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-

Mantıksal YA DA (||)

-
{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
Mantıksal DEĞİL (!){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ÖzellikAndroidAndroid üzerinde ChromeFirefox Mobil (Gecko)IE MobilOpera MobilSafari Mobil
Logical AND (&&){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
Logical OR (||){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
Logical NOT (!){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Ayrıca bakın

- - diff --git "a/files/tr/web/javascript/reference/operat\303\266rler/super/index.html" "b/files/tr/web/javascript/reference/operat\303\266rler/super/index.html" deleted file mode 100644 index 3dd3f62ebf..0000000000 --- "a/files/tr/web/javascript/reference/operat\303\266rler/super/index.html" +++ /dev/null @@ -1,165 +0,0 @@ ---- -title: super -slug: Web/JavaScript/Reference/Operatörler/super -translation_of: Web/JavaScript/Reference/Operators/super ---- -
{{jsSidebar("Operators")}}
- -

super, ebeveyn sınıftaki fonksiyonlara ulaşmak ve onları çağırmak için kullanılan bir ifadedir.

- -

The super.prop and super[expr] expressions are valid in any method definition in both classes and object literals.

- -

Sözdizimi (Syntax)

- -
super([arguments]); // ebeveyn sınıfın constructot'ını çağırır.
-super.functionOnParent([arguments]); // ebeveyn sınıftaki functionOnParent fonksiyonunu çalıştırır.
-
- -

Açıklama

- -

Constructor içinde super ifadesi tek başına kullanılır ve this ifadesinden önce kullanılması zorunludur. Aynı zamanda super ifadesi ebeveyn sınıftaki fonksiyonları çağırmak için de kullanılabilir.

- -

Örnekler

- -

Sınflarda super kullanımı

- -

This code snippet is taken from the classes sample (live demo). Here super() is called to avoid duplicating the constructor parts' that are common between Rectangle and Square.

- -
class Rectangle {
-  constructor(height, width) {
-    this.name = 'Rectangle';
-    this.height = height;
-    this.width = width;
-  }
-  sayName() {
-    console.log('Hi, I am a ', this.name + '.');
-  }
-  get area() {
-    return this.height * this.width;
-  }
-  set area(value) {
-    this._area = value;
-  }
-}
-
-class Square extends Rectangle {
-  constructor(length) {
-    this.height; // ReferenceError, super needs to be called first!
-
-    // Here, it calls the parent class's constructor with lengths
-    // provided for the Rectangle's width and height
-    super(length, length);
-
-    // Note: In derived classes, super() must be called before you
-    // can use 'this'. Leaving this out will cause a reference error.
-    this.name = 'Square';
-  }
-}
- -

Super-calling static methods

- -

You are also able to call super on static methods.

- -
class Rectangle {
-  static logNbSides() {
-    return 'I have 4 sides';
-  }
-}
-
-class Square extends Rectangle {
-  static logDescription() {
-    return super.logNbSides() + ' which are all equal';
-  }
-}
-Square.logDescription(); // 'I have 4 sides which are all equal'
-
- -

Deleting super properties will throw an error

- -

You cannot use the delete operator and super.prop or super[expr] to delete a parent class' property, it will throw a {{jsxref("ReferenceError")}}.

- -
class Base {
-  foo() {}
-}
-class Derived extends Base {
-  delete() {
-    delete super.foo; // this is bad
-  }
-}
-
-new Derived().delete(); // ReferenceError: invalid delete involving 'super'. 
- -

super.prop cannot overwrite non-writable properties

- -

When defining non-writable properties with e.g. {{jsxref("Object.defineProperty")}}, super cannot overwrite the value of the property.

- -
class X {
-  constructor() {
-    Object.defineProperty(this, 'prop', {
-      configurable: true,
-      writable: false,
-      value: 1
-    });
-  }
-}
-
-class Y extends X {
-  constructor() {
-    super();
-  }
-  foo() {
-    super.prop = 2;   // Cannot overwrite the value.
-  }
-}
-
-var y = new Y();
-y.foo(); // TypeError: "prop" is read-only
-console.log(y.prop); // 1
-
- -

Using super.prop in object literals

- -

Super can also be used in the object initializer / literal notation. In this example, two objects define a method. In the second object, super calls the first object's method. This works with the help of {{jsxref("Object.setPrototypeOf()")}} with which we are able to set the prototype of obj2 to obj1, so that super is able to find method1 on obj1.

- -
var obj1 = {
-  method1() {
-    console.log('method 1');
-  }
-}
-
-var obj2 = {
-  method2() {
-    super.method1();
-  }
-}
-
-Object.setPrototypeOf(obj2, obj1);
-obj2.method2(); // logs "method 1"
-
- -

Özellikler

- - - - - - - - - - - - -
Specification
{{SpecName('ESDraft', '#sec-super-keyword', 'super')}}
- -

Tarayıcı uyumluluğu

- - - -

{{Compat("javascript.operators.super")}}

- -

Ayrıca bakınız

- - diff --git "a/files/tr/web/javascript/reference/operat\303\266rler/this/index.html" "b/files/tr/web/javascript/reference/operat\303\266rler/this/index.html" deleted file mode 100644 index 674e577187..0000000000 --- "a/files/tr/web/javascript/reference/operat\303\266rler/this/index.html" +++ /dev/null @@ -1,347 +0,0 @@ ---- -title: this -slug: Web/JavaScript/Reference/Operatörler/this -translation_of: Web/JavaScript/Reference/Operators/this ---- -
{{jsSidebar("Operators")}}
- -

Fonksiyon'un this anahtar kelimesi diğer dillere göre birazcık farklı davranır. Ayrıca strict modu ve non-strict modu arasında farklılıklar bulunur.

- -

Çoğunlukla, this'in değeri fonksiyonun çağrılma biçimine göre belirlenir. Çalışma esnasında değeri değiştirilemez, ve her fonksiyonu çağırışta farklı olabilir. ES5 bu adreste bind method to set the value of a function's this regardless of how it's called.

- -

Sözdizimi

- -
this
- -

Global içerik

- -

Global konumda (fonksiyon dışında), this global nesnesini referans gösterir, strict modunda olmak bu durumu değiştirmez..

- -
console.log(this.document === document); // true
-
-// Web browserlerinde window objesi global objedir.:
-console.log(this === window); // true
-
-this.a = 37;
-console.log(window.a); // 37
-
- -

Function içerik

- -

Fonksiyon içerisinde, this'in değeri fonksiyonun nasıl çağrıldığına bağlıdır..

- -

Basit çağrı

- -
function f1(){
-  return this;
-}
-
-f1() === window; // global obje
-
- -

Bu durumda, this'in değeri çağrı ile ayarlanmaz. Kod strict modda olmadığı sürece, this'in değeri mutlaka obje olmalıdır bu yüzdende default değer olan global objesi döner.

- -
function f2(){
-  "use strict"; // strict modu içerisinde çalıştıralım
-  return this;
-}
-
-f2() === undefined;
-
- -

Strict modu içerisinde, this'in değeri çalıştırılma içeriğine nasıl girdiyse o şekilde kalır. Eğer tanımlanmamışsa, undefined olarak kalır. Ayrıca tüm değerlere eşitlenebilir, örneğin null yada 42 yada "I am not this".

- -
Not: İkinci örnekte, this undefined olmalıdır, çünkü f2 taban belirtilmeden çağrılmıştır. (örn: window.f2()). Bu özellik bazı browserlerde desteklenmemektedir. strict mod henüz geliştirme aşamasındayken çoğu browser yanlış davranarak window objesini döndürür.
- -

Obje methodu cağrısı

- -

Fonksiyon bir objenin methodu olarak çağrıldığında, this çağrıldığı obje olarak atanacaktır.

- -

In the following example, when o.f() is invoked, inside the function this is bound to the o object.

- -
var o = {
-  prop: 37,
-  f: function() {
-    return this.prop;
-  }
-};
-
-console.log(o.f()); // logs 37
-
- -

Note that this behavior is not at all affected by how or where the function was defined. In the previous example, we defined the function inline as the f member during the definition of o. However, we could have just as easily defined the function first and later attached it to o.f. Doing so results in the same behavior:

- -
var o = {prop: 37};
-
-function independent() {
-  return this.prop;
-}
-
-o.f = independent;
-
-console.log(o.f()); // logs 37
-
- -

This demonstrates that it matters only that the function was invoked from the f member of o.

- -

Similarly, the this binding is only affected by the most immediate member reference. In the following example, when we invoke the function, we call it as a method g of the object o.b. This time during execution, this inside the function will refer to o.b. The fact that the object is itself a member of o has no consequence; the most immediate reference is all that matters.

- -
o.b = {g: independent, prop: 42};
-console.log(o.b.g()); // logs 42
-
- -

this on the object's prototype chain

- -

The same notion holds true for methods defined somewhere on the object's prototype chain. If the method is on an object's prototype chain, this refers to the object the method was called on, as if the method was on the object.

- -
var o = {f:function(){ return this.a + this.b; }};
-var p = Object.create(o);
-p.a = 1;
-p.b = 4;
-
-console.log(p.f()); // 5
-
- -

In this example, the object assigned to the variable p doesn't have its own f property, it inherits it from its prototype. But it doesn't matter that the lookup for f eventually finds a member with that name on o; the lookup began as a reference to p.f, so this inside the function takes the value of the object referred to as p. That is, since f is called as a method of p, its this refers to p. This is an interesting feature of JavaScript's prototype inheritance.

- -

this with a getter or setter

- -

Again, the same notion holds true when a function is invoked from a getter or a setter. A function used as getter or setter has its this bound to the object from which the property is being set or gotten.

- -
function modulus(){
-  return Math.sqrt(this.re * this.re + this.im * this.im);
-}
-
-var o = {
-  re: 1,
-  im: -1,
-  get phase(){
-    return Math.atan2(this.im, this.re);
-  }
-};
-
-Object.defineProperty(o, 'modulus', {
-    get: modulus, enumerable:true, configurable:true});
-
-console.log(o.phase, o.modulus); // logs -0.78 1.4142
-
- -

As a constructor

- -

When a function is used as a constructor (with the new keyword), its this is bound to the new object being constructed.

- -

Note: while the default for a constructor is to return the object referenced by this, it can instead return some other object (if the return value isn't an object, then the this object is returned).

- -
/*
- * Constructors work like this:
- *
- * function MyConstructor(){
- *   // Actual function body code goes here.
- *   // Create properties on |this| as
- *   // desired by assigning to them.  E.g.,
- *   this.fum = "nom";
- *   // et cetera...
- *
- *   // If the function has a return statement that
- *   // returns an object, that object will be the
- *   // result of the |new| expression.  Otherwise,
- *   // the result of the expression is the object
- *   // currently bound to |this|
- *   // (i.e., the common case most usually seen).
- * }
- */
-
-function C(){
-  this.a = 37;
-}
-
-var o = new C();
-console.log(o.a); // logs 37
-
-
-function C2(){
-  this.a = 37;
-  return {a:38};
-}
-
-o = new C2();
-console.log(o.a); // logs 38
-
- -

In the last example (C2), because an object was returned during construction, the new object that this was bound to simply gets discarded. (This essentially makes the statement "this.a = 37;" dead code. It's not exactly dead, because it gets executed, but it can be eliminated with no outside effects.)

- -

call and apply

- -

Where a function uses the this keyword in its body, its value can be bound to a particular object in the call using the call or apply methods that all functions inherit from Function.prototype.

- -
function add(c, d){
-  return this.a + this.b + c + d;
-}
-
-var o = {a:1, b:3};
-
-// The first parameter is the object to use as
-// 'this', subsequent parameters are passed as
-// arguments in the function call
-add.call(o, 5, 7); // 1 + 3 + 5 + 7 = 16
-
-// The first parameter is the object to use as
-// 'this', the second is an array whose
-// members are used as the arguments in the function call
-add.apply(o, [10, 20]); // 1 + 3 + 10 + 20 = 34
-
- -

Note that with call and apply, if the value passed as this is not an object, an attempt will be made to convert it to an object using the internal ToObject operation. So if the value passed is a primitive like 7 or 'foo', it will be converted to an Object using the related constructor, so the primitive number 7 is converted to an object as if by new Number(7) and the string 'foo' to an object as if by new String('foo'), e.g.

- -
function bar() {
-  console.log(Object.prototype.toString.call(this));
-}
-
-bar.call(7); // [object Number]
-
- -

The bind method

- -

ECMAScript 5 introduced Function.prototype.bind. Calling f.bind(someObject) creates a new function with the same body and scope as f, but where this occurs in the original function, in the new function it is permanently bound to the first argument of bind, regardless of how the function is being used.

- -
function f(){
-  return this.a;
-}
-
-var g = f.bind({a:"azerty"});
-console.log(g()); // azerty
-
-var o = {a:37, f:f, g:g};
-console.log(o.f(), o.g()); // 37, azerty
-
- -

As a DOM event handler

- -

When a function is used as an event handler, its this is set to the element the event fired from (some browsers do not follow this convention for listeners added dynamically with methods other than addEventListener).

- -
// When called as a listener, turns the related element blue
-function bluify(e){
-  // Always true
-  console.log(this === e.currentTarget);
-  // true when currentTarget and target are the same object
-  console.log(this === e.target);
-  this.style.backgroundColor = '#A5D9F3';
-}
-
-// Get a list of every element in the document
-var elements = document.getElementsByTagName('*');
-
-// Add bluify as a click listener so when the
-// element is clicked on, it turns blue
-for(var i=0 ; i<elements.length ; i++){
-  elements[i].addEventListener('click', bluify, false);
-}
- -

In an in–line event handler

- -

When code is called from an in–line handler, its this is set to the DOM element on which the listener is placed:

- -
<button onclick="alert(this.tagName.toLowerCase());">
-  Show this
-</button>
-
- -

The above alert shows button. Note however that only the outer code has its this set this way:

- -
<button onclick="alert((function(){return this}()));">
-  Show inner this
-</button>
-
- -

In this case, the inner function's this isn't set so it returns the global/window object (i.e. the default object in non–strict mode where this isn't set by the call).

- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES6', '#sec-this-keyword', 'The this keyword')}}{{Spec2('ES6')}} 
{{SpecName('ES5.1', '#sec-11.1.1', 'The this keyword')}}{{Spec2('ES5.1')}} 
{{SpecName('ES3', '#sec-11.1.1', 'The this keyword')}}{{Spec2('ES3')}} 
{{SpecName('ES1', '#sec-11.1.1', 'The this keyword')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.0.
- -

Browser compatibility

- -

{{CompatibilityTable}}

- -
- - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

See also

- - diff --git "a/files/tr/web/javascript/reference/operat\303\266rler/typeof/index.html" "b/files/tr/web/javascript/reference/operat\303\266rler/typeof/index.html" deleted file mode 100644 index deccfd8925..0000000000 --- "a/files/tr/web/javascript/reference/operat\303\266rler/typeof/index.html" +++ /dev/null @@ -1,259 +0,0 @@ ---- -title: typeof -slug: Web/JavaScript/Reference/Operatörler/typeof -translation_of: Web/JavaScript/Reference/Operators/typeof ---- -
{{jsSidebar("Operatörler")}}
- -

Typeof operatörü, değerlendirilmemiş işlenenin türünü gösteren bir dize döndürür.

- -
{{EmbedInteractiveExample("pages/js/expressions-typeof.html")}}
- - - -

Sözdizimi

- -

The typeof operator is followed by its operand:

- -
typeof operand
-or
-typeof (operand)
-
- - - -

Parametreler

- -

operand is an expression representing the object or {{Glossary("Primitive", "primitive")}} whose type is to be returned.

- -

Parantez isteğe bağlıdır.

- -

Description

- -

The following table summarizes the possible return values of typeof. For more information about types and primitives, see also the JavaScript data structure page.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TypeResult
Undefined"undefined"
Null"object" (see below)
Boolean"boolean"
Number"number"
String"string"
Symbol (new in ECMAScript 2015)"symbol"
Host object (provided by the JS environment)Implementation-dependent
Function object (implements [[Call]] in ECMA-262 terms)"function"
Any other object"object"
- -

Örnekler

- -
// Sayılar
-typeof 37 === 'number';
-typeof 3.14 === 'number';
-typeof(42) === 'number';
-typeof Math.LN2 === 'number';
-typeof Infinity === 'number';
-typeof NaN === 'number'; // Despite being "Not-A-Number"
-typeof Number(1) === 'number'; // but never use this form!
-
-
-// Metinler
-typeof '' === 'string';
-typeof 'bla' === 'string';
-typeof '1' === 'string'; // note that a number within a string is still typeof string
-typeof (typeof 1) === 'string'; // typeof always returns a string
-typeof String('abc') === 'string'; // but never use this form!
-
-
-// Booleans
-typeof true === 'boolean';
-typeof false === 'boolean';
-typeof Boolean(true) === 'boolean'; // but never use this form!
-
-
-// Symbols
-typeof Symbol() === 'symbol'
-typeof Symbol('foo') === 'symbol'
-typeof Symbol.iterator === 'symbol'
-
-
-// Undefined
-typeof undefined === 'undefined';
-typeof declaredButUndefinedVariable === 'undefined';
-typeof undeclaredVariable === 'undefined';
-
-
-// Objeler
-typeof {a: 1} === 'object';
-
-// use Array.isArray or Object.prototype.toString.call
-// to differentiate regular objects from arrays
-typeof [1, 2, 4] === 'object';
-
-typeof new Date() === 'object';
-
-
-// The following is confusing. Don't use!
-typeof new Boolean(true) === 'object';
-typeof new Number(1) === 'object';
-typeof new String('abc') === 'object';
-
-
-// Fonksiyonlar
-typeof function() {} === 'function';
-typeof class C {} === 'function';
-typeof Math.sin === 'function';
-
- -

null

- -
// This stands since the beginning of JavaScript
-typeof null === 'object';
-
- -

In the first implementation of JavaScript, JavaScript values were represented as a type tag and a value. The type tag for objects was 0. null was represented as the NULL pointer (0x00 in most platforms). Consequently, null had 0 as type tag, hence the bogus typeof return value. (reference)

- -

A fix was proposed for ECMAScript (via an opt-in), but was rejected. It would have resulted in typeof null === 'null'.

- -

new operatör kullanımı

- -
// All constructor functions while instantiated with 'new' keyword will always be typeof 'object'
-var str = new String('String');
-var num = new Number(100);
-
-typeof str; // It will return 'object'
-typeof num; // It will return 'object'
-
-// But there is a exception in case of Function constructor of Javascript
-
-var func = new Function();
-
-typeof func; // It will return 'function'
-
- -

Parantezlere ihtiyaç var

- -
// Parentheses will be very much useful to determine the data type for expressions.
-var iData = 99;
-
-typeof iData + ' Wisen'; // It will return 'number Wisen'
-typeof (iData + ' Wisen'); // It will return 'string'
-
-
-
- -

Düzenli İfadeler

- -

Callable regular expressions were a non-standard addition in some browsers.

- -
typeof /s/ === 'function'; // Chrome 1-12 Non-conform to ECMAScript 5.1
-typeof /s/ === 'object';   // Firefox 5+  Conform to ECMAScript 5.1
-
- -

Temporal Dead Zone errors

- -

Before ECMAScript 2015, typeof was always guaranteed to return a string for any operand it was supplied with. But with the addition of non-hoisted, block-scoped let and const, using typeof on let and const variables in a block before they are declared will throw a ReferenceError. This is in contrast with undeclared variables, for which typeof will return 'undefined'. Block scoped variables are in a "temporal dead zone" from the start of the block until the initialization is processed, during which, it will throw an error if accessed.

- -
typeof undeclaredVariable === 'undefined';
-typeof newLetVariable; let newLetVariable; // ReferenceError
-typeof newConstVariable; const newConstVariable = 'hello'; // ReferenceError
-
- -

İstisnalar

- -

All current browsers expose a non-standard host object {{domxref("document.all")}} with type Undefined.

- -
typeof document.all === 'undefined';
-
- -

Although the specification allows custom type tags for non-standard exotic objects, it requires those type tags to be different from the predefined ones. The case of document.all having type tag 'undefined' must be classified as an exceptional violation of the rules.

- -

Özellikler

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ESDraft', '#sec-typeof-operator', 'The typeof Operator')}}{{Spec2('ESDraft')}}
{{SpecName('ES6', '#sec-typeof-operator', 'The typeof Operator')}}{{Spec2('ES6')}}
{{SpecName('ES5.1', '#sec-11.4.3', 'The typeof Operator')}}{{Spec2('ES5.1')}}
{{SpecName('ES3', '#sec-11.4.3', 'The typeof Operator')}}{{Spec2('ES3')}}
{{SpecName('ES1', '#sec-11.4.3', 'The typeof Operator')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.1.
- -

Browser compatibility

- - - -

{{Compat("javascript.operators.typeof")}}

- -

IE özel notlar

- -

On IE 6, 7, and 8 a lot of host objects are objects and not functions. For example:

- -
typeof alert === 'object'
- -

Bakabilirsiniz

- - -- cgit v1.2.3-54-g00ecf