diff options
Diffstat (limited to 'files/ar/web/javascript/reference/classes/constructor/index.html')
-rw-r--r-- | files/ar/web/javascript/reference/classes/constructor/index.html | 132 |
1 files changed, 0 insertions, 132 deletions
diff --git a/files/ar/web/javascript/reference/classes/constructor/index.html b/files/ar/web/javascript/reference/classes/constructor/index.html deleted file mode 100644 index 135948c80b..0000000000 --- a/files/ar/web/javascript/reference/classes/constructor/index.html +++ /dev/null @@ -1,132 +0,0 @@ ---- -title: المنشئ (constructor) -slug: Web/JavaScript/Reference/Classes/constructor -tags: - - جافاسكريبت -translation_of: Web/JavaScript/Reference/Classes/constructor ---- -<div>{{jsSidebar("Classes")}}</div> - -<p dir="rtl">الـ <code>constructor</code> هي ميثود خاصة لإنشاء وتهيئة الاوبجكت(كائن) داخل (فئة)<code>class</code>.</p> - -<div>{{EmbedInteractiveExample("pages/js/classes-constructor.html")}}</div> - - - -<h2 dir="rtl" id="بناء_الجملة">بناء الجملة</h2> - -<pre class="syntaxbox">constructor([arguments]) { ... }</pre> - -<h2 dir="rtl" id="الوصف">الوصف</h2> - -<p dir="rtl">يمكننا إستخدام تلك الميثود لمرة واحده فقط ، وفي حال إستخدمنا <code>constructor</code> ﻷكثر من مرة في نفس الفئة الـ class سيحدث {{jsxref("SyntaxError")}} إيرور .</p> - -<p>A constructor can use the <code>super</code> keyword to call the constructor of a parent class.</p> - -<p dir="rtl">إذا لم تحدد ميثود إنشاء سيتم تحديد منشئ بشكل تلقائي.</p> - -<p><br> - <sup>If you do not specify a constructor method, a default constructor is used.</sup></p> - -<h2 dir="rtl" id="أمثلة">أمثلة</h2> - -<h3 dir="rtl" id="إٍستخدام_الميثود_(اسلوب)_الـconstructor">إٍستخدام الميثود (اسلوب) الـ<code>constructor </code></h3> - -<p dir="rtl">ذلك الكود تم أخذه ولصقة من <a href="https://github.com/GoogleChrome/samples/blob/gh-pages/classes-es6/index.html">classes sample</a> (<a href="https://googlechrome.github.io/samples/classes-es6/index.html">live demo</a>)</p> - -<pre class="brush: js">class Square extends Polygon { - constructor(length) { - // Here, it calls the parent class' constructor with lengths - // provided for the Polygon'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'; - } - - get area() { - return this.height * this.width; - } - - set area(value) { - this.area = value; - } -}</pre> - -<h3 dir="rtl" id="مثال_آخر">مثال آخر</h3> - -<p dir="rtl">إنظر إلى ذلك الكود</p> - -<pre class="brush: js">class Polygon { - constructor() { - this.name = "Polygon"; - } -} - -class Square extends Polygon { - constructor() { - super(); - } -} - -class Rectangle {} - -Object.setPrototypeOf(Square.prototype, Rectangle.prototype); - -console.log(Object.getPrototypeOf(Square.prototype) === Polygon.prototype); //false -console.log(Object.getPrototypeOf(Square.prototype) === Rectangle.prototype); //true - -let newInstance = new Square(); -console.log(newInstance.name); //Polygon</pre> - -<p dir="rtl">هنا البروتوتيب فئة الـ <strong>Square</strong> تغيرت ولكن الكونستركتور (المنشئ) مبني على فئة الـ<strong>Polygon </strong>والتي تطلب عندما نقوم بإنشاء حالة مماثلة للـ <strong>Square </strong>مرة أخرى</p> - -<h3 dir="rtl" id="الإنشاء_الإفتراضي">الإنشاء الإفتراضي</h3> - -<p dir="rtl">ذكرنا سابقا أنه في حال عدم تحديدك لكونستركتور (منشئ) سيتم تحديد الكونستركتور بشكل إفتراضي ، وبالنسبة للكلاسز (الفئات) الاولية يكون الكونستركتور الخاص بها كما يلي :-</p> - -<pre class="brush: js">constructor() {} -</pre> - -<p dir="rtl">أما الفئات المشتقة فتكون بالشكل التالي</p> - -<pre class="brush: js">constructor(...args) { - super(...args); -}</pre> - -<h2 id="Specifications">Specifications</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ES2015', '#sec-static-semantics-constructormethod', 'Constructor Method')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-static-semantics-constructormethod', 'Constructor Method')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 dir="rtl" id="دعم_المتصفحات">دعم المتصفحات</h2> - - - -<p>{{Compat("javascript.classes.constructor")}}</p> - -<h2 id="أنظر_أيضا">أنظر أيضا</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/super">super()</a></li> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/class"><code>class</code> expression</a></li> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/class"><code>class</code> declaration</a></li> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Classes">Classes</a></li> -</ul> |