From de5c456ebded0e038adbf23db34cc290c8829180 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:49:24 +0100 Subject: unslug pl: move --- .../global_objects/object/constructor/index.html | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 files/pl/web/javascript/reference/global_objects/object/constructor/index.html (limited to 'files/pl/web/javascript/reference/global_objects/object/constructor') diff --git a/files/pl/web/javascript/reference/global_objects/object/constructor/index.html b/files/pl/web/javascript/reference/global_objects/object/constructor/index.html new file mode 100644 index 0000000000..3de20f1350 --- /dev/null +++ b/files/pl/web/javascript/reference/global_objects/object/constructor/index.html @@ -0,0 +1,49 @@ +--- +title: Object.prototype.constructor +slug: Web/JavaScript/Referencje/Obiekty/Object/constructor +tags: + - JavaScript + - Object + - Property +translation_of: Web/JavaScript/Reference/Global_Objects/Object/constructor +--- +

{{JSRef}}

+ +

Podsumowanie

+ +

Określa funkcję tworzącą prototyp obiektu. Należy pamiętać, że wartość tej własności jest referencją do funkcji, a nie łańcuchem znaków zawierającym jej nazwę.

+ +

Opis

+ +

Wszystkie obiekty dziedziczą własność constructor z ich prototypu (prototype):

+ +
var o = {};
+o.constructor === Object; // true
+
+var a = [];
+a.constructor === Array; // true
+
+var n = new Number(3);
+n.constructor === Number; // true
+
+ +

Przykłady

+ +

Przykład: Wyświetlanie konstruktora obiektu

+ +

Poniższy przykład tworzy prototyp, Drzewo i obiekt tego typu sosna. Następnie wyświetlana jest własność constructor obiektu Drzewo.

+ +
function Drzewo(nazwa) {
+   this.nazwa=nazwa;
+}
+
+sosna = new Drzewo("sosna");
+console.log("sosna.constructor to " + sosna.constructor)
+
+ +

Przykład ten wyświetla:

+ +
sosna.constructor to function Drzewo(nazwa) {
+   this.nazwa = nazwa;
+}
+
-- cgit v1.2.3-54-g00ecf