aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/javascript/reference/global_objects/object/hasownproperty/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/de/web/javascript/reference/global_objects/object/hasownproperty/index.html')
-rw-r--r--files/de/web/javascript/reference/global_objects/object/hasownproperty/index.html203
1 files changed, 203 insertions, 0 deletions
diff --git a/files/de/web/javascript/reference/global_objects/object/hasownproperty/index.html b/files/de/web/javascript/reference/global_objects/object/hasownproperty/index.html
new file mode 100644
index 0000000000..1d990d3bfa
--- /dev/null
+++ b/files/de/web/javascript/reference/global_objects/object/hasownproperty/index.html
@@ -0,0 +1,203 @@
+---
+title: Object.prototype.hasOwnProperty()
+slug: Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
+tags:
+ - JavaScript
+ - Method
+ - Object
+ - Prototype
+translation_of: Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
+---
+<div>{{JSRef}}</div>
+
+<p>Die Methode <code><strong>hasOwnProperty() </strong></code>gibt einen boolean Wert zurück abhängig von der Existenz des gegebenen <strong>Attributs</strong> in einem <strong>Objekt.</strong></p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox"><code><var>obj</var>.hasOwnProperty(<var>prop</var>)</code></pre>
+
+<h3 id="Parameter">Parameter</h3>
+
+<dl>
+ <dt><code>prop</code></dt>
+ <dd>Der Name des Attributs auf dessen Existenz im Objekt geprüft wird</dd>
+</dl>
+
+<h3 id="Rückgabewert">Rückgabewert</h3>
+
+<p>Ein {{jsxref("Boolean")}} der besagt, ob eine Eigenschaft in dem gegebenen Objekte vorhanden ist oder nicht.</p>
+
+<h2 id="Beschreibung">Beschreibung</h2>
+
+<p>Jedes  untergeordnete Objekt / jeder untergeordneter Wert in einem Objekt trägt die hasOwnProperty Methode mit sich. Diese Methode ermöglicht das Nachfragen eines untergeordneten Wertes/Objekts innerhalb eines Objekts. Anders als die {{jsxref("Operators/in", "in")}} Methode ermöglicht die hasOwnProperty Methode keinen Zugriff auf die Kindeskinder eines Objekts.</p>
+
+<h2 id="Beispiele">Beispiele</h2>
+
+<h3 id="Einsatz_von_hasOwnProperty_zur_Überprüfung_der_Existenz_eines_Attributs_in_einem_Objekt">Einsatz von hasOwnProperty zur Überprüfung der Existenz eines Attributs in einem Objekt</h3>
+
+<p>Das folgende Beispiel prüft ob das Objekt <code>o</code> ein Attribut mit dem Namen <code>prop</code> beinhaltet.</p>
+
+<pre class="brush: js">o = new Object();
+o.prop = 'exists';
+
+function changeO() {
+ o.newprop = o.prop;
+ delete o.prop;
+}
+
+o.hasOwnProperty('prop'); // gibt true zurück
+changeO();
+o.hasOwnProperty('prop'); // gibt false zurück
+</pre>
+
+<h3 id="Direkter_Nachfolger_vs_Geerbtes_Attribut">Direkter Nachfolger vs Geerbtes Attribut</h3>
+
+<p>Das folgende Beispiel unterscheidet zwischen direkten Kind-Attributen eines Objekts und den Attributen die durch die prototype - Verarbeitung entstehen.</p>
+
+<pre class="brush: js">o = new Object();
+o.prop = 'exists';
+o.hasOwnProperty('prop'); // gibt true zurück
+o.hasOwnProperty('toString'); // gibt false zurück
+o.hasOwnProperty('hasOwnProperty'); // gibt false zurück
+</pre>
+
+<h3 id="Über_die_Eigenschaften_eines_Objektes_iterieren">Über die Eigenschaften eines Objektes iterieren</h3>
+
+<p>Das folgende Beispiel zeigt, wie man über die Eigenschaften eines Objektes iteriert ohne vererbte Eigenschaften auszuführen. Zu Beachten ist, dass eine {{jsxref("Statements/for...in", "for...in")}} Schleife nur über zählbare (enumerable) Eigenschaften iteriert, jedoch sollte man durch diese Einschränkung nicht annehmen, dass nicht-zählbare Eigenschaften gezeigt werden, denn <code>hasOwnProperty</code> selbst kann nur auf zählbare Eigenschaften angewendet werden (wie auch die {{jsxref("Object.getOwnPropertyNames()")}} Funktion):</p>
+
+<pre class="brush: js">var buz = {
+ fog: 'stack'
+};
+
+for (var name in buz) {
+ if (buz.hasOwnProperty(name)) {
+ console.log('this is fog (' + name + ') for sure. Value: ' + buz[name]);
+ }
+ else {
+ console.log(name); // toString or something else
+ }
+}
+</pre>
+
+<h3 id="Einsatz_von_hasOwnProperty_als_Eigenschaftsname">Einsatz von <code>hasOwnProperty</code> als Eigenschaftsname</h3>
+
+<p>JavaScript schützt die den Eigenschaftsnamen <code>hasOwnProperty</code> nicht. Dadurch ist es möglich, dass ein Objekt eine Eigenschaft mit diesem namen hat. Das ermöglicht es eine externe <code>hasOwnProperty</code> Funktion zu benutzen:</p>
+
+<pre class="brush: js">var foo = {
+ hasOwnProperty: function() {
+ return false;
+ },
+ bar: 'Here be dragons'
+};
+
+foo.hasOwnProperty('bar'); // always returns false
+
+// Use another Object's hasOwnProperty and call it with 'this' set to foo
+({}).hasOwnProperty.call(foo, 'bar'); // true
+
+// It's also possible to use the hasOwnProperty property from the Object prototype for this purpose
+Object.prototype.hasOwnProperty.call(foo, 'bar'); // true
+</pre>
+
+<p>Zu beachten ist, dass im letzten Fall kein neues Objekt erstellt wird.</p>
+
+<h2 id="Spezifikationen">Spezifikationen</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Spezifikation</th>
+ <th scope="col">Status</th>
+ <th scope="col">Kommentar</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td>Initiale Definition. Implementiert in JavaScript 1.5.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.2.4.5', 'Object.prototype.hasOwnProperty')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-object.prototype.hasownproperty', 'Object.prototype.hasOwnProperty')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-object.prototype.hasownproperty', 'Object.prototype.hasOwnProperty')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browserkompatibilität">Browserkompatibilität</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Edge</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Firefox OS</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>iOS WebKit<br>
+ <sup><sub>(Safari/Chrome/Firefox/etc)</sub></sup></th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/de/docs/Web/JavaScript/Aufzählbarkeit_und_Zugehörigkeit_von_Eigenschaften">Aufzählbarkeit und Zugehörigkeit von Eigenschaften</a></li>
+ <li>{{jsxref("Object.getOwnPropertyNames()")}}</li>
+ <li>{{jsxref("Statements/for...in", "for...in")}}</li>
+ <li>{{jsxref("Operators/in", "in")}}</li>
+ <li><a href="/de/docs/Web/JavaScript/Inheritance_and_the_prototype_chain">Vererbung und die Prototypenkette</a></li>
+</ul>