{"id":16228,"date":"2024-10-21T17:35:22","date_gmt":"2024-10-21T14:05:22","guid":{"rendered":"https:\/\/www.itpiran.net\/blog\/?p=16228"},"modified":"2024-10-21T17:35:22","modified_gmt":"2024-10-21T14:05:22","slug":"factory-functions-vs-constructors","status":"publish","type":"post","link":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/","title":{"rendered":"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f"},"content":{"rendered":"<h2 id=\"%d9%85%d9%82%d8%af%d9%85%d9%87\">\u0645\u0642\u062f\u0645\u0647<\/h2>\n<p>\u0628\u0631\u0627\u06cc \u062f\u0631\u06a9 \u0645\u0641\u0647\u0648\u0645 factory functions \u0648 constructors\u060c \u0627\u0628\u062a\u062f\u0627 \u0628\u0627\u06cc\u062f \u062a\u0648\u0627\u0628\u0639 \u0648 \u0627\u0634\u06cc\u0627\u0621 \u0631\u0627 \u062f\u0631\u06a9 \u06a9\u0646\u06cc\u062f.<\/p>\n<p>\u0627\u06af\u0631 \u062a\u0639\u062f\u0627\u062f \u0632\u06cc\u0627\u062f\u06cc \u0627\u0632 \u0627\u0634\u06cc\u0627\u0621 \u0628\u0627 \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627 \u0648 \u0639\u0645\u0644\u06a9\u0631\u062f\u0647\u0627\u06cc \u0645\u0634\u0627\u0628\u0647 \u0627\u06cc\u062c\u0627\u062f \u0645\u06cc \u06a9\u0646\u06cc\u062f\u060c \u0645\u0645\u06a9\u0646 \u0627\u0633\u062a \u062e\u0633\u062a\u0647 \u06a9\u0646\u0646\u062f\u0647 \u0648 \u062a\u06a9\u0631\u0627\u0631\u06cc \u0628\u0627\u0634\u062f. \u0645\u0627 \u0645\u06cc \u062e\u0648\u0627\u0647\u06cc\u0645 \u0627\u0635\u0644 \u062d\u0641\u0638 \u06a9\u062f D.R.Y \u0631\u0627 \u06a9\u0647 \u0645\u062e\u0641\u0641 &#8220;Don&#8217;t Repeat Yourself&#8221; \u0627\u0633\u062a \u0631\u0627 \u062f\u0631 \u0646\u0638\u0631 \u062f\u0627\u0634\u062a\u0647 \u0628\u0627\u0634\u06cc\u0645. \u0627\u0644\u06af\u0648\u0647\u0627\u06cc \u062a\u0627\u0628\u0639\u06cc \u0648\u062c\u0648\u062f \u062f\u0627\u0631\u062f \u06a9\u0647 \u0645\u06cc \u062a\u0648\u0627\u0646\u062f \u0628\u0647 \u0645\u0627 \u06a9\u0645\u06a9 \u06a9\u0646\u062f \u06a9\u062f \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u060c \u062a\u0645\u06cc\u0632\u062a\u0631 \u0648 \u06a9\u0627\u0631\u0622\u0645\u062f\u062a\u0631 \u0628\u0646\u0648\u06cc\u0633\u06cc\u0645. \u062a\u0648\u0627\u0628\u0639 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0648 \u062a\u0648\u0627\u0628\u0639 \u0633\u0627\u0632\u0646\u062f\u0647 \u0645\u06cc \u062a\u0648\u0627\u0646\u0646\u062f \u0627\u06cc\u0646 \u06a9\u0627\u0631 \u0631\u0627 \u0627\u0646\u062c\u0627\u0645 \u062f\u0647\u0646\u062f\u060c \u0627\u0645\u0627 \u0627\u0632 \u06a9\u062f\u0627\u0645 \u06cc\u06a9 \u0628\u0627\u06cc\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u06cc\u062f\u061f \u0628\u06cc\u0627\u06cc\u06cc\u062f \u06a9\u0645\u06cc \u0639\u0645\u06cc\u0642 \u062a\u0631 \u062f\u0631 \u0645\u0648\u0631\u062f \u0627\u06cc\u0646\u06a9\u0647 \u0686\u0647 \u06a9\u0627\u0631\u06a9\u0631\u062f\u0647\u0627\u06cc \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0648 \u0633\u0627\u0632\u0646\u062f\u0647 \u0647\u0627 \u0647\u0633\u062a\u0646\u062f\u060c \u0686\u0647 \u06a9\u0627\u0631\u06cc \u0645\u06cc \u062a\u0648\u0627\u0646\u0646\u062f \u0648 \u0686\u0647 \u06a9\u0627\u0631\u06cc \u0646\u0645\u06cc \u062a\u0648\u0627\u0646\u0646\u062f \u0627\u0646\u062c\u0627\u0645 \u062f\u0647\u0646\u062f \u0648 \u0634\u0628\u0627\u0647\u062a \u0647\u0627 \u0648 \u062a\u0641\u0627\u0648\u062a \u0647\u0627 \u063a\u0648\u0637\u0647 \u0648\u0631 \u0634\u0648\u06cc\u0645.<\/p>\n<h2 id=\"factory-function-%da%86%db%8c%d8%b3%d8%aa%d8%9f\">Factory Function \u0686\u06cc\u0633\u062a\u061f<\/h2>\n<p>factory function \u0631\u0627 \u0645\u06cc \u062a\u0648\u0627\u0646 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u06cc\u06a9 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0648\u0627\u0642\u0639\u06cc \u062f\u0631 \u0646\u0638\u0631 \u06af\u0631\u0641\u062a \u06a9\u0647 \u0645\u0648\u0627\u062f \u0627\u0648\u0644\u06cc\u0647 \u0631\u0627 \u062f\u0631\u06cc\u0627\u0641\u062a \u0645\u06cc \u06a9\u0646\u062f \u0648 \u0645\u062d\u0635\u0648\u0644\u0627\u062a \u0645\u062a\u0639\u062f\u062f\u06cc \u0631\u0627 \u0628\u0647 \u0633\u0631\u0639\u062a \u062a\u0648\u0644\u06cc\u062f \u0645\u06cc \u06a9\u0646\u062f. \u0627\u0632 \u0637\u0631\u0641 \u062f\u06cc\u06af\u0631\u060c \u062a\u0648\u0627\u0628\u0639 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647\u060c \u0648\u0631\u0648\u062f\u06cc \u0647\u0627\u06cc \u062e\u0627\u0635\u06cc \u0631\u0627 \u062f\u0631\u06cc\u0627\u0641\u062a \u0645\u06cc \u06a9\u0646\u0646\u062f \u0648 \u0627\u0632 \u0622\u0646 \u0648\u0631\u0648\u062f\u06cc \u0647\u0627 \u0628\u0631\u0627\u06cc \u0627\u06cc\u062c\u0627\u062f \u06cc\u06a9 \u0634\u06cc \u062c\u062f\u06cc\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u06a9\u0646\u0646\u062f. \u0628\u0646\u0627\u0628\u0631\u0627\u06cc\u0646\u060c \u0686\u06af\u0648\u0646\u0647 \u0627\u06cc\u0646 \u0648\u0627\u0642\u0639\u0627\u064b \u0645\u06cc \u062a\u0648\u0627\u0646\u062f \u0628\u0631\u0627\u06cc \u0645\u0627 \u0645\u0641\u06cc\u062f \u0628\u0627\u0634\u062f\u061f \u0645\u0627 \u0628\u0647 \u0633\u0627\u062f\u06af\u06cc \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u0645 \u0647\u0631 \u0634\u06cc \u0631\u0627 \u0628\u0647 \u0635\u0648\u0631\u062a \u062c\u062f\u0627\u06af\u0627\u0646\u0647 \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u0645\u060c \u0627\u0645\u0627 \u0645\u0645\u06a9\u0646 \u0627\u0633\u062a \u0645\u062f\u062a\u06cc \u0637\u0648\u0644 \u0628\u06a9\u0634\u062f. \u0627\u06af\u0631 \u062f\u0631 \u062d\u0627\u0644 \u0627\u06cc\u062c\u0627\u062f \u0627\u0634\u06cc\u0627\u06cc\u06cc \u0628\u0627 \u0648\u06cc\u0698\u06af\u06cc\u200c\u0647\u0627\u06cc \u06cc\u06a9\u0633\u0627\u0646 \u0648 \u0645\u0642\u0627\u062f\u06cc\u0631 \u0645\u062a\u0641\u0627\u0648\u062a \u0647\u0633\u062a\u06cc\u062f\u060c \u0627\u06cc\u062c\u0627\u062f \u06cc\u06a9 \u062a\u0627\u0628\u0639 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u062f \u0627\u06cc\u0646 \u0641\u0631\u0622\u06cc\u0646\u062f \u0631\u0627 \u0633\u0631\u06cc\u0639\u200c\u062a\u0631 \u06a9\u0646\u062f.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>const car1 = {\r\nmake: 'Toyota',\r\nmodel: 'Tacoma',\r\nyear: 2018,\r\nfuelType: 'gas', \r\nbodyType: 'mid-size pick-up truck',\r\ngetFullName() {\r\nreturn `${this.year} ${this.make} ${this.model}`;\r\n}\r\n}\r\nconsole.log(car1.getFullName()); \/\/ =&gt; 2018 Toyota Tacoma<\/code><\/pre>\n<\/div>\n<p>\u062f\u0631 \u0645\u062b\u0627\u0644 \u0628\u0627\u0644\u0627\u060c \u06cc\u06a9 \u0634\u06cc \u0627\u06cc\u062c\u0627\u062f \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u06a9\u0647 \u06cc\u06a9 \u0645\u0627\u0634\u06cc\u0646 \u062e\u0627\u0635 \u0631\u0627 \u062a\u0648\u0635\u06cc\u0641 \u0645\u06cc \u06a9\u0646\u062f. \u062d\u0627\u0644\u0627 \u0628\u06cc\u0627\u06cc\u06cc\u062f \u06cc\u06a9 \u0634\u06cc \u0645\u0634\u0627\u0628\u0647 \u0628\u0627 \u0627\u06cc\u0646 \u06cc\u06a9\u06cc \u0628\u0633\u0627\u0632\u06cc\u0645.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>const car2 = {\r\nmake: 'Tesla', \r\nmodel: 'Model S',\r\nyear: 2018,\r\nfuelType: 'electric',\r\nbodyType: 'sedan',\r\ngetFullName() {\r\nreturn `${this.year} ${this.make} ${this.model}`;\r\n}\r\n}\r\nconsole.log(car2.getFullName()); \/\/ =&gt; 2018 Tesla Model S <\/code><\/pre>\n<\/div>\n<p>\u0627\u06a9\u0646\u0648\u0646\u060c \u0645\u0646 \u0645\u06cc \u062a\u0648\u0627\u0646\u0645 \u0628\u0647 \u0633\u0627\u062e\u062a \u0627\u0634\u06cc\u0627\u0621 \u0645\u0627\u0634\u06cc\u0646 \u0647\u0627\u06cc \u0628\u06cc\u0634\u062a\u0631\u06cc \u0627\u062f\u0627\u0645\u0647 \u062f\u0647\u0645\u060c \u0627\u0645\u0627 \u0686\u0647 \u06a9\u0633\u06cc \u0628\u0631\u0627\u06cc \u0622\u0646 \u0648\u0642\u062a \u062f\u0627\u0631\u062f\u060c \u062f\u0631\u0633\u062a \u0627\u0633\u062a\u061f \u0628\u06cc\u0627\u06cc\u06cc\u062f \u0628\u0628\u06cc\u0646\u06cc\u0645 \u06a9\u0647 \u0627\u06cc\u0646 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u06cc\u06a9 \u0639\u0645\u0644\u06a9\u0631\u062f \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0686\u06af\u0648\u0646\u0647 \u0627\u0633\u062a.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function createCar (make, model, year, fuelType, bodyType) {\r\nreturn {\r\nmake: make, \r\nmodel: model, \r\nyear: year, \r\nfuelType: fuelType, \r\nbodyType: bodyType,\r\ngetFullName() {\r\nreturn `${year} ${make} ${model}`;\r\n}\r\n}\r\n}<\/code><\/pre>\n<\/div>\n<p>\u0645\u0627 \u0627\u06a9\u0646\u0648\u0646 \u06cc\u06a9 \u062a\u0627\u0628\u0639 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u062f\u0627\u0631\u06cc\u0645 \u06a9\u0647 \u0627\u0634\u06cc\u0627\u0621 \u062c\u062f\u06cc\u062f\u06cc \u0631\u0627 \u0628\u0631\u0627\u06cc \u0645\u0627 \u0627\u06cc\u062c\u0627\u062f \u0645\u06cc \u06a9\u0646\u062f. \u0627\u06a9\u0646\u0648\u0646\u060c \u062a\u0646\u0647\u0627 \u06a9\u0627\u0631\u06cc \u06a9\u0647 \u0628\u0627\u06cc\u062f \u0627\u0646\u062c\u0627\u0645 \u062f\u0647\u06cc\u0645 \u0627\u06cc\u0646 \u0627\u0633\u062a \u06a9\u0647 \u062f\u0627\u062f\u0647 \u0647\u0627 \u0631\u0627 \u0627\u0631\u0633\u0627\u0644 \u06a9\u0646\u06cc\u0645 \u0648 \u0628\u0647 \u062a\u0627\u0628\u0639 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0627\u062c\u0627\u0632\u0647 \u062f\u0647\u06cc\u0645 \u06a9\u0627\u0631 \u062e\u0648\u062f \u0631\u0627 \u0627\u0646\u062c\u0627\u0645 \u062f\u0647\u062f.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function createCar (make, model, year, fuelType, bodyType) {\r\nreturn {\r\nmake: make, \r\nmodel: model, \r\nyear: year, \r\nfuelType: fuelType, \r\nbodyType: bodyType,\r\ngetFullName() {\r\nreturn `${year} ${make} ${model}`;\r\n}\r\n}\r\n}\r\nconst car1 = createCar('Toyota', 'Tacoma', 2018, 'gas', 'mid-size pick-up truck');\r\nconst car2 = createCar('Tesla', 'Model S', 2018, 'electric', 'sedan');\r\nconsole.log(car1.getFullName()); \/\/ =&gt; 2018 Toyota Tacoma\r\nconsole.log(car2.getFullName()); \/\/ =&gt; 2018 Tesla Model S<\/code><\/pre>\n<\/div>\n<p>\u0634\u0645\u0627 \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u062f \u0647\u0631 \u062a\u0639\u062f\u0627\u062f \u0634\u06cc \u0631\u0627 \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0627\u0628\u0639 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0628\u0647 \u062c\u0627\u06cc \u062a\u06a9\u0631\u0627\u0631 \u06a9\u062f \u0628\u0633\u0627\u0632\u06cc\u062f.<\/p>\n<h2 id=\"constructors-%da%86%db%8c%d8%b3%d8%aa%d8%9f\">constructors \u0686\u06cc\u0633\u062a\u061f<\/h2>\n<p>\u062a\u0627\u0628\u0639 \u0633\u0627\u0632\u0646\u062f\u0647 \u06cc\u06a9\u06cc \u062f\u06cc\u06af\u0631 \u0627\u0632 \u0627\u0644\u06af\u0648\u0647\u0627\u06cc \u062c\u0627\u0648\u0627 \u0627\u0633\u06a9\u0631\u06cc\u067e\u062a \u0627\u0633\u062a \u06a9\u0647 \u0628\u0633\u06cc\u0627\u0631 \u0634\u0628\u06cc\u0647 \u062a\u0648\u0627\u0628\u0639 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0627\u0633\u062a. \u0627\u06af\u0631\u0686\u0647\u060c \u0628\u0631 \u062e\u0644\u0627\u0641 \u062a\u0648\u0627\u0628\u0639 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647\u060c \u062a\u0648\u0627\u0628\u0639 \u0633\u0627\u0632\u0646\u062f\u0647 \u062f\u0631 \u0648\u0627\u0642\u0639 \u06cc\u06a9 \u0634\u06cc \u0631\u0627 \u0628\u0631 \u0646\u0645\u06cc \u06af\u0631\u062f\u0627\u0646\u062f. \u0628\u0631\u0627\u06cc \u0627\u06cc\u062c\u0627\u062f \u0627\u0634\u06cc\u0627\u0621 \u0645\u062e\u062a\u0644\u0641 \u0628\u0627 \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u06cc\u06a9\u0633\u0627\u0646\u060c \u0628\u0627\u06cc\u062f \u0627\u0632 \u06a9\u0644\u06cc\u062f\u0648\u0627\u0698\u0647 &#8220;new&#8221; \u0648 \u06a9\u0644\u0645\u0647 \u06a9\u0644\u06cc\u062f\u06cc &#8220;this&#8221; \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u06cc\u0645. \u0628\u0627 \u0627\u06cc\u0646 \u06af\u0641\u062a\u0647\u060c \u0628\u06cc\u0627\u06cc\u06cc\u062f \u0628\u0628\u06cc\u0646\u06cc\u0645 \u06a9\u0647 \u0686\u06af\u0648\u0646\u0647 \u062a\u0648\u0627\u0628\u0639 \u0633\u0627\u0632\u0646\u062f\u0647 \u0628\u0647 \u0635\u0648\u0631\u062a \u0628\u0635\u0631\u06cc \u06a9\u0627\u0631 \u0645\u06cc \u06a9\u0646\u0646\u062f.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function Car(make, model, year, fuelType, bodyType) {\r\nthis.make = make\r\nthis.model = model \r\nthis.year = year\r\nthis.fuelType = fuelType\r\nthis.bodyType = bodyType\r\nthis.getFullName = () =&gt; {\r\nreturn `${this.year} ${this.make} ${this.model}`;\r\n}\r\n}<\/code><\/pre>\n<\/div>\n<p>\u062f\u0631 \u0645\u062b\u0627\u0644 \u0628\u0627\u0644\u0627\u060c \u062a\u0627\u0628\u0639 \u0633\u0627\u0632\u0646\u062f\u0647 \u0628\u0633\u06cc\u0627\u0631 \u0634\u0628\u06cc\u0647 \u06cc\u06a9 \u062a\u0627\u0628\u0639 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0627\u0633\u062a\u060c \u0628\u0647 \u062c\u0632 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u06a9\u0644\u0645\u0647 \u06a9\u0644\u06cc\u062f\u06cc &#8220;this&#8221;.&#8221;this&#8221; \u0628\u0647 \u062a\u0627\u0628\u0639 \u0633\u0627\u0632\u0646\u062f\u0647 \u0627\u06cc \u0627\u0634\u0627\u0631\u0647 \u062f\u0627\u0631\u062f \u06a9\u0647 \u0634\u06cc \u0646\u0645\u0648\u0646\u0647 \u0631\u0627 \u0627\u06cc\u062c\u0627\u062f \u06a9\u0631\u062f\u0647 \u0627\u0633\u062a. \u0628\u0647 \u0639\u0628\u0627\u0631\u062a \u062f\u06cc\u06af\u0631\u060c &#8220;this&#8221; \u062f\u0631 \u06cc\u06a9 \u062a\u0627\u0628\u0639 \u0633\u0627\u0632\u0646\u062f\u0647 \u0627\u0631\u0632\u0634\u06cc \u0646\u062f\u0627\u0631\u062f. \u0634\u0645\u0627 \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u062f \u0622\u0646 \u0631\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u06cc\u06a9 \u067e\u0627\u06cc\u0647 \u0628\u0631\u0627\u06cc \u0634\u06cc \u062c\u062f\u06cc\u062f \u062f\u0631 \u0646\u0638\u0631 \u0628\u06af\u06cc\u0631\u06cc\u062f.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function Car(make, model, year, fuelType, bodyType) {\r\nthis.make = make\r\nthis.model = model \r\nthis.year = year\r\nthis.fuelType = fuelType\r\nthis.bodyType = bodyType\r\nthis.getFullName = () =&gt; {\r\nreturn `${this.year} ${this.make} ${this.model}`;\r\n}\r\n}\r\nconst car1 = new car('Toyota', 'Tacoma', 2018, 'gas', 'mid-size pick-up truck');\r\nconst car2 = new car('Tesla', 'Model S', 2018, 'electric', 'sedan');\r\nconsole.log(car1.getFullName()); \/\/ =&gt; 2018 Toyota Tacoma\r\nconsole.log(car2.getFullName()); \/\/ =&gt; 2018 Tesla Model S<\/code><\/pre>\n<\/div>\n<p>\u0628\u0631\u0627\u06cc \u0627\u06cc\u062c\u0627\u062f \u0627\u0634\u06cc\u0627 \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 \u0633\u0627\u0632\u0646\u062f\u0647\u060c \u0627\u0632 \u06a9\u0644\u0645\u0647 \u06a9\u0644\u06cc\u062f\u06cc \u062f\u06cc\u06af\u0631\u06cc \u0628\u0647 \u0646\u0627\u0645 &#8220;\u062c\u062f\u06cc\u062f&#8221; \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u06a9\u0646\u06cc\u0645. \u0648\u0642\u062a\u06cc \u0627\u0632 \u0639\u0628\u0627\u0631\u062a &#8220;\u062c\u062f\u06cc\u062f&#8221; \u062f\u0631 \u0645\u0642\u0627\u0628\u0644 \u0641\u0631\u0627\u062e\u0648\u0627\u0646\u06cc \u062a\u0627\u0628\u0639 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u06a9\u0646\u06cc\u062f\u060c \u062c\u0627\u0648\u0627 \u0627\u0633\u06a9\u0631\u06cc\u067e\u062a \u0628\u0647 \u0637\u0648\u0631 \u062e\u0648\u062f\u06a9\u0627\u0631 \u062f\u0648 \u06a9\u0627\u0631 \u0631\u0627 \u0628\u0631\u0627\u06cc \u0645\u0627 \u0627\u0646\u062c\u0627\u0645 \u0645\u06cc \u062f\u0647\u062f: \u062f\u0631 \u062f\u0627\u062e\u0644 \u062a\u0627\u0628\u0639\u060c \u06cc\u06a9 \u0634\u06cc \u062e\u0627\u0644\u06cc \u0628\u0627 \u0646\u0627\u0645 &#8220;this&#8221; \u0627\u06cc\u062c\u0627\u062f \u0645\u06cc \u06a9\u0646\u062f. \u0634\u06cc &#8220;this&#8221; \u0631\u0627 \u0628\u0647 \u0639\u0628\u0627\u0631\u062a\u06cc \u06a9\u0647 \u0627\u0628\u062a\u062f\u0627 \u062a\u0627\u0628\u0639 \u0631\u0627 \u0641\u0631\u0627\u062e\u0648\u0627\u0646\u06cc \u06a9\u0631\u062f\u0647 \u0628\u0648\u062f \u0628\u0631\u0645\u06cc \u06af\u0631\u062f\u0627\u0646\u062f.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function Car(make, model, year, fuelType, bodyType) {\r\n\/\/ const this = {};\r\nthis.make = make\r\nthis.model = model \r\nthis.year = year\r\nthis.fuelType = fuelType\r\nthis.bodyType = bodyType\r\nthis.getFullName = () =&gt; {\r\nreturn `${this.year} ${this.make} ${this.model}`;\r\n}\r\n\/\/ return this;\r\n}\r\nconst car1 = new car('Toyota', 'Tacoma', 2018, 'gas', 'mid-size pick-up truck');\r\nconst car2 = new car('Tesla', 'Model S', 2018, 'electric', 'sedan');\r\nconsole.log(car1.getFullName()); \/\/ =&gt; 2018 Toyota Tacoma\r\nconsole.log(car2.getFullName()); \/\/ =&gt; 2018 Tesla Model S<\/code><\/pre>\n<\/div>\n<h2 id=\"%d8%a7%d8%b1%d8%ab\">\u0627\u0631\u062b<\/h2>\n<p>\u0648\u0631\u0627\u062b\u062a \u0646\u0642\u0634 \u0645\u0647\u0645\u06cc \u062f\u0631 \u062a\u0641\u0627\u0648\u062a \u0639\u0645\u0644\u06a9\u0631\u062f\u0647\u0627\u06cc \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0648 \u0633\u0627\u0632\u0646\u062f\u0647 \u062f\u0627\u0631\u062f.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function createCar (make, model, year, fuelType, bodyType) {\r\nreturn {\r\nmake: make, \r\nmodel: model, \r\nyear: year, \r\nfuelType: fuelType, \r\nbodyType: bodyType,\r\ngetFullName() {\r\nreturn `${year} ${make} ${model}`;\r\n}\r\n}\r\n}\r\nconst car1 = createCar('Toyota', 'Tacoma', 2018, 'gas', 'mid-size pick-up truck');\r\nconst car2 = createCar('Tesla', 'Model S', 2018, 'electric', 'sedan'); \r\ncar1.getFullName = function() {\r\nreturn `My ${fuelType} ${bodyType} is a ${year} ${make} ${model}`;\r\n}\r\nconsole.log(car1.getFullName()); \/\/ =&gt; My gas mid-size pick-up truck is a 2018 Toyota Tacoma\r\nconsole.log(car2.getFullName()); \/\/ =&gt; 2018 Tesla Model S<\/code><\/pre>\n<\/div>\n<p>\u0628\u06cc\u0627\u06cc\u06cc\u062f \u0628\u0647 \u0627\u0648\u0644\u06cc\u0646 \u0645\u062b\u0627\u0644 \u0627\u0632 \u0639\u0645\u0644\u06a9\u0631\u062f \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0628\u0627\u0632\u06af\u0631\u062f\u06cc\u0645. \u0627\u06af\u0631 \u0628\u062e\u0648\u0627\u0647\u06cc\u0645 ()car1.getFullName \u0631\u0627 \u0645\u062c\u062f\u062f\u0627\u064b \u0627\u0639\u0644\u0627\u0645 \u06a9\u0646\u06cc\u0645\u060c \u0686\u0647\u061f \u062e\u0628\u060c car1.getFullName() \u0648 car2.getFullName() \u062a\u0627\u0628\u0639 \u06cc\u06a9\u0633\u0627\u0646\u06cc \u062f\u0631 \u062d\u0627\u0641\u0638\u0647 \u0646\u06cc\u0633\u062a\u0646\u062f. \u0647\u0631 \u0634\u06cc\u0621 \u06a9\u067e\u06cc \u062e\u0648\u062f \u0631\u0627 \u0627\u0632 \u062a\u0627\u0628\u0639 \u062f\u0631\u06cc\u0627\u0641\u062a \u0645\u06cc \u06a9\u0646\u062f. \u0628\u0647 \u0627\u06cc\u0646 \u0645\u0639\u0646\u06cc \u06a9\u0647 \u0648\u0642\u062a\u06cc \u062a\u0627\u0628\u0639 \u06cc\u06a9 \u0634\u06cc \u0627\u06cc\u062c\u0627\u062f \u0645\u06cc\u200c\u06a9\u0646\u062f \u0648 \u0622\u0646 \u0631\u0627 \u0628\u0631\u0645\u06cc\u200c\u06af\u0631\u062f\u0627\u0646\u062f\u060c \u0648\u06cc\u0698\u06af\u06cc\u200c\u0647\u0627 \u0648 \u0645\u0642\u0627\u062f\u06cc\u0631 \u0631\u0627 \u06a9\u067e\u06cc \u06a9\u0631\u062f\u0647 \u0648 \u0628\u0647 \u0647\u0631 \u0634\u06cc\u0626\u06cc \u06a9\u0647 \u062a\u0627\u0628\u0639 \u0631\u0627 \u0641\u0631\u0627\u062e\u0648\u0627\u0646\u06cc \u0645\u06cc\u200c\u06a9\u0646\u062f\u060c \u0645\u062a\u0635\u0644 \u0645\u06cc\u200c\u06a9\u0646\u062f.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function car(make, model, year, fuelType, bodyType) {\r\n\/\/ const this = {};\r\nthis.make = make\r\nthis.model = model \r\nthis.year = year\r\nthis.fuelType = fuelType\r\nthis.bodyType = bodyType\r\nthis.getFullName = () =&gt; {\r\nreturn `${this.year} ${this.make} ${this.model}`;\r\n}\r\n\/\/ return this;\r\n}\r\nconst car1 = new car('Toyota', 'Tacoma', 2018, 'gas', 'mid-size pick-up truck');\r\nconst car2 = new car('Tesla', 'Model S', 2018, 'electric', 'sedan');\r\nconsole.log(car1); \/\/ =&gt; car {make: 'Toyota', model: 'Tacoma' , etc.}<\/code><\/pre>\n<\/div>\n<p>\u062d\u0627\u0644\u0627 \u0628\u06cc\u0627\u06cc\u06cc\u062f \u0646\u06af\u0627\u0647\u06cc \u0628\u0647 \u062a\u0627\u0628\u0639 \u0633\u0627\u0632\u0646\u062f\u0647 \u062e\u0648\u062f \u062f\u0631 \u0628\u0627\u0644\u0627 \u0628\u06cc\u0646\u062f\u0627\u0632\u06cc\u0645. \u0648\u0642\u062a\u06cc \u0633\u0627\u0632\u0646\u062f\u0647 \u0633\u0627\u062e\u062a\u0647 \u0645\u06cc \u0634\u0648\u062f\u060c \u0646\u0645\u0648\u0646\u0647 \u0627\u0648\u0644\u06cc\u0647 \u062e\u0648\u062f \u0631\u0627 \u062f\u0627\u0631\u062f. \u0647\u0646\u06af\u0627\u0645\u06cc \u06a9\u0647 \u06cc\u06a9 \u0634\u06cc\u0621 \u062c\u062f\u06cc\u062f \u0645\u0627\u0634\u06cc\u0646 \u0631\u0627 \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u06a9\u0644\u0645\u0647 \u06a9\u0644\u06cc\u062f\u06cc &#8220;new&#8221; \u0627\u06cc\u062c\u0627\u062f \u0645\u06cc \u06a9\u0646\u06cc\u0645\u060c \u0646\u0645\u0648\u0646\u0647 \u0627\u06cc \u0627\u0632 \u0646\u0648\u0639 \u0645\u0627\u0634\u06cc\u0646 \u0627\u06cc\u062c\u0627\u062f \u0645\u06cc \u06a9\u0646\u062f. \u0628\u0647 \u0639\u0628\u0627\u0631\u062a \u062f\u06cc\u06af\u0631\u060c \u0646\u0645\u0648\u0646\u0647 \u0627\u0648\u0644\u06cc\u0647 car1 \u0627\u0632 \u0646\u0648\u0639 \u062e\u0648\u062f\u0631\u0648 \u0627\u0633\u062a. \u0627\u06a9\u0646\u0648\u0646 car1 \u0627\u0632 \u0633\u0627\u0632\u0646\u062f\u0647 \u062e\u0648\u062f\u0631\u0648 \u0627\u0631\u062b \u0645\u06cc \u0628\u0631\u062f. \u0627\u06cc\u0646 \u0628\u0647 \u0645\u0627 \u0627\u062c\u0627\u0632\u0647 \u0645\u06cc \u062f\u0647\u062f \u062a\u0627 \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc\u06cc \u0631\u0627 \u0628\u0647 \u0646\u0645\u0648\u0646\u0647 \u0627\u0648\u0644\u06cc\u0647 \u062e\u0648\u062f\u0631\u0648 \u0627\u0636\u0627\u0641\u0647 \u06a9\u0646\u06cc\u0645.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>Car.prototype.sentence = function() {\r\nreturn `My ${this.fuelType} ${this.bodyType} is a ${this.year} ${this.make} ${this.model}`;\r\n}<\/code><\/pre>\n<\/div>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>console.log(car1); \/\/ =&gt; Car {\r\n\/\/ make: 'Toyota',\r\n\/\/ model: 'Tacoma',\r\n\/\/ year: 2018,\r\n\/\/ fuelType: 'gas',\r\n\/\/ bodyType: 'mid-size pick-up truck',\r\n\/\/ getFullName: [Function (anonymous)]\r\n\/\/ }<\/code><\/pre>\n<\/div>\n<p>\u062a\u0648\u062c\u0647 \u062f\u0627\u0634\u062a\u0647 \u0628\u0627\u0634\u06cc\u062f \u06a9\u0647 \u062a\u0627\u0628\u0639 \u062c\u0645\u0644\u0647 \u0645\u0633\u062a\u0642\u06cc\u0645\u0627\u064b \u0628\u0647 \u062e\u0648\u062f \u0633\u0627\u0632\u0646\u062f\u0647 \u062e\u0648\u062f\u0631\u0648 \u0627\u0636\u0627\u0641\u0647 \u0646\u0645\u06cc \u0634\u0648\u062f.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>console.log(Car.prototype); \/\/ =&gt; { sentence: [Function (anonymous)] }\r\n<\/code><\/pre>\n<\/div>\n<p>\u0627\u0645\u0627 \u0648\u0642\u062a\u06cc \u0646\u0645\u0648\u0646\u0647 \u0627\u0648\u0644\u06cc\u0647 \u0622\u0646 \u0631\u0627 \u0628\u0631\u0631\u0633\u06cc \u0645\u06cc \u06a9\u0646\u06cc\u0645\u060c \u0622\u0646\u062c\u0627\u0633\u062a! \u0627\u06a9\u0646\u0648\u0646 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u06cc\u0645 \u0628\u0647 \u062a\u0627\u0628\u0639 \u062c\u062f\u06cc\u062f \u0627\u0636\u0627\u0641\u0647 \u0634\u062f\u0647 \u062f\u0633\u062a\u0631\u0633\u06cc \u067e\u06cc\u062f\u0627 \u06a9\u0646\u06cc\u0645.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>console.log(car1.sentence()); \/\/ =&gt; My gas mid-size pick-up truck is a 2018 Toyota Tacoma\r\nconsole.log(car2.sentence()); \/\/ =&gt; My electric sedan is a 2018 Tesla Model S<\/code><\/pre>\n<\/div>\n<p>\u0627\u06a9\u0646\u0648\u0646 \u06a9\u0647 \u0645\u06cc \u062f\u0627\u0646\u06cc\u0645 \u0647\u0631 \u0639\u0645\u0644\u06cc\u0627\u062a \u0686\u06af\u0648\u0646\u0647 \u06a9\u0627\u0631 \u0645\u06cc \u06a9\u0646\u062f\u060c \u0633\u0624\u0627\u0644 \u0627\u06cc\u0646 \u0627\u0633\u062a: \u06a9\u062f\u0627\u0645 \u06cc\u06a9 \u0631\u0627 \u0628\u0627\u06cc\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u06cc\u0645\u061f \u0647\u0631 \u062f\u0648 \u0645\u06cc \u062a\u0648\u0627\u0646\u0646\u062f \u0646\u062a\u06cc\u062c\u0647 \u06cc\u06a9\u0633\u0627\u0646\u06cc \u0631\u0627 \u0628\u0631\u0627\u06cc \u0634\u0645\u0627 \u0628\u0647 \u0627\u0631\u0645\u063a\u0627\u0646 \u0628\u06cc\u0627\u0648\u0631\u0646\u062f. \u0633\u0627\u0632\u0646\u062f\u0647 \u0647\u0627 \u0632\u0645\u0627\u0646\u06cc \u0639\u0627\u0644\u06cc \u0647\u0633\u062a\u0646\u062f \u06a9\u0647 \u0645\u06cc \u062e\u0648\u0627\u0647\u06cc\u062f \u06cc\u06a9 \u0648\u06cc\u0698\u06af\u06cc \u0631\u0627 \u0627\u0632 \u0647\u0631 \u0634\u06cc \u06a9\u0647 \u0627\u0632 \u0633\u0627\u0632\u0646\u062f\u0647 \u0628\u0647 \u0627\u0631\u062b \u0645\u06cc \u0628\u0631\u062f \u0627\u0636\u0627\u0641\u0647 \u06cc\u0627 \u062d\u0630\u0641 \u06a9\u0646\u06cc\u062f. \u0628\u0627 \u0627\u06cc\u0646 \u062d\u0627\u0644\u060c \u062f\u0631\u06a9 \u0639\u0645\u0644\u06a9\u0631\u062f\u0647\u0627\u06cc \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0645\u06cc \u062a\u0648\u0627\u0646\u062f \u0633\u0627\u062f\u0647 \u062a\u0631 \u0628\u0627\u0634\u062f\u060c \u0632\u06cc\u0631\u0627 \u062f\u0631 \u067e\u0627\u06cc\u0627\u0646 \u0631\u0648\u0632\u060c \u0627\u06cc\u0646 \u0641\u0642\u0637 \u06cc\u06a9 \u0639\u0645\u0644\u06a9\u0631\u062f \u0627\u0633\u062a. \u0628\u0631\u0627\u06cc \u0639\u0645\u0644\u06a9\u0631\u062f\u0647\u0627\u06cc \u06a9\u0627\u0631\u062e\u0627\u0646\u0647\u060c \u0644\u0627\u0632\u0645 \u0646\u06cc\u0633\u062a \u06a9\u0644\u0645\u0647 \u06a9\u0644\u06cc\u062f\u06cc &#8220;\u062c\u062f\u06cc\u062f&#8221; \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u0645. \u0628\u0627 \u0642\u062f\u0631\u062a \u0628\u0633\u062a\u0647 \u0634\u062f\u0646 \u0645\u06cc \u062a\u0648\u0627\u0646\u062f \u0627\u0646\u0639\u0637\u0627\u0641 \u067e\u0630\u06cc\u0631\u062a\u0631 \u0628\u0627\u0634\u062f. \u0628\u0627 \u0622\u0646\u060c \u0645\u0627 \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u0645 \u0686\u06cc\u0632\u06cc \u0628\u0647 \u0646\u0627\u0645 &#8220;\u062d\u0631\u06cc\u0645 \u062e\u0635\u0648\u0635\u06cc \u062f\u0627\u062f\u0647 \u0647\u0627&#8221; \u0631\u0627 \u0627\u0646\u062c\u0627\u0645 \u062f\u0647\u06cc\u0645. \u0628\u06cc\u0627\u06cc\u06cc\u062f \u0628\u0647 \u06cc\u06a9 \u0645\u062b\u0627\u0644 \u062f\u06cc\u06af\u0631 \u0646\u06af\u0627\u0647 \u06a9\u0646\u06cc\u0645 \u06a9\u0647 \u062a\u0648\u0636\u06cc\u062d \u0645\u06cc \u062f\u0647\u062f \u0686\u06af\u0648\u0646\u0647 \u0627\u06cc\u0646 \u06a9\u0627\u0631 \u0645\u06cc \u06a9\u0646\u062f.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function createCar(make, model, year) {\r\nreturn {\r\ngetFullName() {\r\nreturn `${year} ${make} ${model}`;\r\n}\r\n}\r\n}\r\nconst car1 = createCar('Toyota', 'Tacoma', 2018); \r\nconsole.log(car1.getFullName()); \/\/ =&gt; 2018 Toyota Tacoma\r\nconsole.log(car1.make); \/\/ =&gt; undefined\r\nconsole.log(car1); \/\/ =&gt; { getFullName: [Function: getFullName] }<\/code><\/pre>\n<\/div>\n<h2 id=\"%d9%86%d8%aa%db%8c%d8%ac%d9%87\">\u0646\u062a\u06cc\u062c\u0647<\/h2>\n<p>\u062f\u0631 \u0645\u062c\u0645\u0648\u0639\u060c \u0646\u06a9\u062a\u0647 \u0645\u0647\u0645 \u062f\u0631 \u0645\u0648\u0631\u062f \u0646\u0648\u0634\u062a\u0646 \u06a9\u062f \u062e\u0648\u062f \u0627\u06cc\u0646 \u0627\u0633\u062a \u06a9\u0647 \u0647\u06cc\u0686 \u0686\u06cc\u0632 \u0644\u0632\u0648\u0645\u0627\u064b \u0627\u0634\u062a\u0628\u0627\u0647 \u0646\u06cc\u0633\u062a. \u0631\u0648\u0634 \u062e\u0648\u0628\u06cc \u0628\u0631\u0627\u06cc \u062a\u0645\u06cc\u0632 \u0648 \u06a9\u0648\u062a\u0627\u0647 \u0646\u06af\u0647 \u062f\u0627\u0634\u062a\u0646 \u06a9\u062f \u0645\u0627 \u0648\u062c\u0648\u062f \u062f\u0627\u0631\u062f. \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 \u0648 \u062a\u0648\u0627\u0628\u0639 \u0633\u0627\u0632\u0646\u062f\u0647 \u062f\u0631 \u062c\u0627\u06cc\u06cc \u06a9\u0647 \u0641\u06a9\u0631 \u0645\u06cc \u06a9\u0646\u06cc\u062f \u0628\u0631\u0627\u06cc \u0645\u0648\u0631\u062f \u0634\u0645\u0627 \u0628\u0647\u062a\u0631\u06cc\u0646 \u0627\u0633\u062a \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u06cc\u062f.<\/p>\n","protected":false},"excerpt":{"rendered":"\u0645\u0642\u062f\u0645\u0647 \u0628\u0631\u0627\u06cc \u062f\u0631\u06a9 \u0645\u0641\u0647\u0648\u0645 factory functions \u0648 constructors\u060c \u0627\u0628\u062a\u062f\u0627 \u0628\u0627\u06cc\u062f \u062a\u0648\u0627\u0628\u0639 \u0648 \u0627\u0634\u06cc\u0627\u0621 \u0631\u0627 \u062f\u0631\u06a9 \u06a9\u0646\u06cc\u062f. \u0627\u06af\u0631 \u062a\u0639\u062f\u0627\u062f&hellip;\n","protected":false},"author":1,"featured_media":16229,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_yoast_wpseo_focuskw":"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"","_yoast_wpseo_canonical":"","_yoast_wpseo_opengraph-description":"","_yoast_wpseo_opengraph-image":"","_yoast_wpseo_twitter-description":"","_yoast_wpseo_twitter-image":"","_yoast_wpseo_focuskeywords":"","_yoast_wpseo_primary_category":"193","footnotes":""},"categories":[193],"tags":[384,435],"class_list":{"0":"post-16228","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-tutorials","8":"tag-java-script","9":"tag-programming"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f - \u0628\u0644\u0627\u06af ITPiran<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/\" \/>\n<meta property=\"og:locale\" content=\"fa_IR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f - \u0628\u0644\u0627\u06af ITPiran\" \/>\n<meta property=\"og:description\" content=\"\u0645\u0642\u062f\u0645\u0647 \u0628\u0631\u0627\u06cc \u062f\u0631\u06a9 \u0645\u0641\u0647\u0648\u0645 factory functions \u0648 constructors\u060c \u0627\u0628\u062a\u062f\u0627 \u0628\u0627\u06cc\u062f \u062a\u0648\u0627\u0628\u0639 \u0648 \u0627\u0634\u06cc\u0627\u0621 \u0631\u0627 \u062f\u0631\u06a9 \u06a9\u0646\u06cc\u062f. \u0627\u06af\u0631 \u062a\u0639\u062f\u0627\u062f&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/\" \/>\n<meta property=\"og:site_name\" content=\"\u0628\u0644\u0627\u06af ITPiran\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-21T14:05:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.itpiran.net\/2024\/10\/21161700\/constructor-factory-function.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1793\" \/>\n\t<meta property=\"og:image:height\" content=\"1110\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u0646\u0648\u0634\u062a\u0647\u200c\u0634\u062f\u0647 \u0628\u062f\u0633\u062a\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u0632\u0645\u0627\u0646 \u062a\u0642\u0631\u06cc\u0628\u06cc \u0628\u0631\u0627\u06cc \u062e\u0648\u0627\u0646\u062f\u0646\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u062f\u0642\u06cc\u0642\u0647\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/person\\\/04ed27b919baca468a2273f8e4318f81\"},\"headline\":\"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f\",\"datePublished\":\"2024-10-21T14:05:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/\"},\"wordCount\":34,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/10\\\/21161700\\\/constructor-factory-function.jpg\",\"keywords\":[\"Java Script\",\"programming\"],\"articleSection\":[\"\u0622\u0645\u0648\u0632\u0634\u06cc\"],\"inLanguage\":\"fa-IR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/\",\"name\":\"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f - \u0628\u0644\u0627\u06af ITPiran\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/10\\\/21161700\\\/constructor-factory-function.jpg\",\"datePublished\":\"2024-10-21T14:05:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/#breadcrumb\"},\"inLanguage\":\"fa-IR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fa-IR\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/#primaryimage\",\"url\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/10\\\/21161700\\\/constructor-factory-function.jpg\",\"contentUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/10\\\/21161700\\\/constructor-factory-function.jpg\",\"width\":1793,\"height\":1110},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/factory-functions-vs-constructors\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u0622\u0645\u0648\u0632\u0634\u06cc\",\"item\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/category\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/\",\"name\":\"\u0628\u0644\u0627\u06af ITPiran\",\"description\":\"\u0627\u062e\u0628\u0627\u0631 \u0648 \u0645\u0642\u0627\u0644\u0627\u062a \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fa-IR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#organization\",\"name\":\"\u0628\u0644\u0627\u06af \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646\",\"alternateName\":\"ITPIran Blog\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fa-IR\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/cdn.itpiran.net\\\/2023\\\/12\\\/27150508\\\/cropped-ITPIRAN-BLOG-LOGO-2.png\",\"contentUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2023\\\/12\\\/27150508\\\/cropped-ITPIRAN-BLOG-LOGO-2.png\",\"width\":512,\"height\":512,\"caption\":\"\u0628\u0644\u0627\u06af \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646\"},\"image\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/person\\\/04ed27b919baca468a2273f8e4318f81\",\"name\":\"admin\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f - \u0628\u0644\u0627\u06af ITPiran","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/","og_locale":"fa_IR","og_type":"article","og_title":"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f - \u0628\u0644\u0627\u06af ITPiran","og_description":"\u0645\u0642\u062f\u0645\u0647 \u0628\u0631\u0627\u06cc \u062f\u0631\u06a9 \u0645\u0641\u0647\u0648\u0645 factory functions \u0648 constructors\u060c \u0627\u0628\u062a\u062f\u0627 \u0628\u0627\u06cc\u062f \u062a\u0648\u0627\u0628\u0639 \u0648 \u0627\u0634\u06cc\u0627\u0621 \u0631\u0627 \u062f\u0631\u06a9 \u06a9\u0646\u06cc\u062f. \u0627\u06af\u0631 \u062a\u0639\u062f\u0627\u062f&hellip;","og_url":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/","og_site_name":"\u0628\u0644\u0627\u06af ITPiran","article_published_time":"2024-10-21T14:05:22+00:00","og_image":[{"width":1793,"height":1110,"url":"https:\/\/cdn.itpiran.net\/2024\/10\/21161700\/constructor-factory-function.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u0646\u0648\u0634\u062a\u0647\u200c\u0634\u062f\u0647 \u0628\u062f\u0633\u062a":"admin","\u0632\u0645\u0627\u0646 \u062a\u0642\u0631\u06cc\u0628\u06cc \u0628\u0631\u0627\u06cc \u062e\u0648\u0627\u0646\u062f\u0646":"3 \u062f\u0642\u06cc\u0642\u0647"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/#article","isPartOf":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/"},"author":{"name":"admin","@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/person\/04ed27b919baca468a2273f8e4318f81"},"headline":"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f","datePublished":"2024-10-21T14:05:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/"},"wordCount":34,"commentCount":0,"publisher":{"@id":"https:\/\/www.itpiran.net\/blog\/#organization"},"image":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.itpiran.net\/2024\/10\/21161700\/constructor-factory-function.jpg","keywords":["Java Script","programming"],"articleSection":["\u0622\u0645\u0648\u0632\u0634\u06cc"],"inLanguage":"fa-IR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/","url":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/","name":"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f - \u0628\u0644\u0627\u06af ITPiran","isPartOf":{"@id":"https:\/\/www.itpiran.net\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/#primaryimage"},"image":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.itpiran.net\/2024\/10\/21161700\/constructor-factory-function.jpg","datePublished":"2024-10-21T14:05:22+00:00","breadcrumb":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/#breadcrumb"},"inLanguage":"fa-IR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/"]}]},{"@type":"ImageObject","inLanguage":"fa-IR","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/#primaryimage","url":"https:\/\/cdn.itpiran.net\/2024\/10\/21161700\/constructor-factory-function.jpg","contentUrl":"https:\/\/cdn.itpiran.net\/2024\/10\/21161700\/constructor-factory-function.jpg","width":1793,"height":1110},{"@type":"BreadcrumbList","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/factory-functions-vs-constructors\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.itpiran.net\/blog\/"},{"@type":"ListItem","position":2,"name":"\u0622\u0645\u0648\u0632\u0634\u06cc","item":"https:\/\/www.itpiran.net\/blog\/category\/tutorials\/"},{"@type":"ListItem","position":3,"name":"Factory Functions \u0648 Constructor \u0686\u0647 \u0647\u0633\u062a\u0646\u062f \u061f"}]},{"@type":"WebSite","@id":"https:\/\/www.itpiran.net\/blog\/#website","url":"https:\/\/www.itpiran.net\/blog\/","name":"\u0628\u0644\u0627\u06af ITPiran","description":"\u0627\u062e\u0628\u0627\u0631 \u0648 \u0645\u0642\u0627\u0644\u0627\u062a \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646","publisher":{"@id":"https:\/\/www.itpiran.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.itpiran.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fa-IR"},{"@type":"Organization","@id":"https:\/\/www.itpiran.net\/blog\/#organization","name":"\u0628\u0644\u0627\u06af \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646","alternateName":"ITPIran Blog","url":"https:\/\/www.itpiran.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"fa-IR","@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdn.itpiran.net\/2023\/12\/27150508\/cropped-ITPIRAN-BLOG-LOGO-2.png","contentUrl":"https:\/\/cdn.itpiran.net\/2023\/12\/27150508\/cropped-ITPIRAN-BLOG-LOGO-2.png","width":512,"height":512,"caption":"\u0628\u0644\u0627\u06af \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646"},"image":{"@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/person\/04ed27b919baca468a2273f8e4318f81","name":"admin","url":"https:\/\/www.itpiran.net\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/posts\/16228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/comments?post=16228"}],"version-history":[{"count":2,"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/posts\/16228\/revisions"}],"predecessor-version":[{"id":16231,"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/posts\/16228\/revisions\/16231"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/media\/16229"}],"wp:attachment":[{"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/media?parent=16228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/categories?post=16228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/wp-json\/wp\/v2\/tags?post=16228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}