From 9bdd6bdcb0db13209f371f345df8b500c055b22c Mon Sep 17 00:00:00 2001 From: MaHdi Date: Sat, 18 Sep 2021 15:21:39 +0430 Subject: [PATCH 01/10] Translate a part of article --- .../06-function-object/article.md | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/1-js/06-advanced-functions/06-function-object/article.md b/1-js/06-advanced-functions/06-function-object/article.md index c588d6f36..617a46243 100644 --- a/1-js/06-advanced-functions/06-function-object/article.md +++ b/1-js/06-advanced-functions/06-function-object/article.md @@ -1,20 +1,20 @@ -# Function object, NFE +# شیء تابع، NFE -As we already know, a function in JavaScript is a value. +همانطور که می‌دانیم، یک تابع در جاوااسکریپت یک مقدار است. -Every value in JavaScript has a type. What type is a function? +هر مقداری در جاوااسکریپت نوع دارد. تابع از چه نوعی است؟ -In JavaScript, functions are objects. +در جاوااسکریپت، تابع‌ها شیء هستند. -A good way to imagine functions is as callable "action objects". We can not only call them, but also treat them as objects: add/remove properties, pass by reference etc. +یک راه خوب برای تصور کردن تابع‌ها، فکر کردن به آنها به عنوان «شیءهای عملکردی» قابل فراخوانی است. ما نه تنها می‌توانیم آنها را فرا بخوانیم بلکه می‌توانیم با آنها مانند شیءها رفتار کنیم: ویژگی‌ها را اضافه/حذف کنیم، آنها را توسط مرجع رد و بدل کنیم و غیره. -## The "name" property +## ویژگی "name" -Function objects contain some useable properties. +شیء تابع‌ها چند ویژگی قابل استفاده دارند. -For instance, a function's name is accessible as the "name" property: +برای مثال، اسم یک تابع با ویژگی "name" قابل دسترس است: ```js run function sayHi() { @@ -24,29 +24,29 @@ function sayHi() { alert(sayHi.name); // sayHi ``` -What's kind of funny, the name-assigning logic is smart. It also assigns the correct name to a function even if it's created without one, and then immediately assigned: +منطق مقداردهی اسم، هوشمندانه و جالب است. حتی زمانی که یک تابع بدون اسم ساخته و سریعا تخصیص داده شود، اسم درستی را برای مقداردهی استفاده می‌کند: ```js run let sayHi = function() { alert("Hi"); }; -alert(sayHi.name); // sayHi (there's a name!) +alert(sayHi.name); // sayHi (!یک اسم دارد) ``` -It also works if the assignment is done via a default value: +اگر مقداردهی توسط یک مقدار پیش‌فرض انجام شود هم کار می‌کند: ```js run function f(sayHi = function() {}) { - alert(sayHi.name); // sayHi (works!) + alert(sayHi.name); // sayHi (!کار می‌کند) } f(); ``` -In the specification, this feature is called a "contextual name". If the function does not provide one, then in an assignment it is figured out from the context. +در مشخصات، این خاصیت «اسم زمینه‌ای» نامیده شده است. اگر تابع اسمی نداشته باشد، سپس در مقداردهی، از زمینه موجود پیدا می‌شود. -Object methods have names too: +متدهای شیءها هم اسم دارند: ```js run let user = { @@ -65,21 +65,21 @@ alert(user.sayHi.name); // sayHi alert(user.sayBye.name); // sayBye ``` -There's no magic though. There are cases when there's no way to figure out the right name. In that case, the name property is empty, like here: +اگرچه هیچ جادویی وجود ندارد. مواردی وجود دارند که راهی برای فهمیدن اسم درست وجود ندارد. در این صورت، ویژگی اسم (name) خالی است، مثل اینجا: ```js run -// function created inside array +// تابع درون آرایه ساخته شده است let arr = [function() {}]; -alert( arr[0].name ); // -// the engine has no way to set up the right name, so there is none +alert( arr[0].name ); // <رشته خالی> +// موتور راهی برای دریافت اسم درست ندارد، پس هیچی وجود ندارد ``` -In practice, however, most functions do have a name. +اگرچه در عمل، اکثر تابع‌ها اسم دارند. -## The "length" property +## ویژگی "length" -There is another built-in property "length" that returns the number of function parameters, for instance: +یک ویژگی درون‌ساخت دیگر به نام "length" وجود دارد که تعداد پارامترهای تابع را برمی‌گرداند، برای مثال: ```js run function f1(a) {} @@ -91,20 +91,20 @@ alert(f2.length); // 2 alert(many.length); // 2 ``` -Here we can see that rest parameters are not counted. +اینجا می‌بینیم که پارامترهای رِست شمرده نمی‌شوند. -The `length` property is sometimes used for [introspection](https://en.wikipedia.org/wiki/Type_introspection) in functions that operate on other functions. +ویژگی `length` بعضی اوقات برای [درون‌نگری](https://en.wikipedia.org/wiki/Type_introspection) در تابع‌هایی که بر روی تابع‌های دیگر کاری انجام می‌دهند استفاده می‌شود. -For instance, in the code below the `ask` function accepts a `question` to ask and an arbitrary number of `handler` functions to call. +برای مثال، در کد زیر تابع `ask` یک `question` (سوال) برای پرسیدن و تعدادی تابع `handler` (کنترل‌کننده) برای فراخوانی دریافت می‌کند. -Once a user provides their answer, the function calls the handlers. We can pass two kinds of handlers: +زمانی که کاربر جواب خود را وارد کرد، تابع کنترل‌کننده‌ها را فراخوانی می‌کند. ما می‌توانیم دو نوع کنترل‌کننده را رد کنیم: -- A zero-argument function, which is only called when the user gives a positive answer. -- A function with arguments, which is called in either case and returns an answer. +- یک تابع با صفر آرگومان که فقط زمانی که کاربر یک جواب مثبت می‌دهد فراخوانی شود. +- یک تابع با چند آرگومان که در هر شرایطی فراخوانی می‌شود و یک جواب برمی‌گرداند. -To call `handler` the right way, we examine the `handler.length` property. +برای اینکه `handler` را به درستی فراخوانی کنیم، ویژگی `handler.length` را بررسی می‌کنیم. -The idea is that we have a simple, no-arguments handler syntax for positive cases (most frequent variant), but are able to support universal handlers as well: +ایده این است که ما یک سینتکس کنترل‌کننده ساده و بدون آرگومان برای موارد مثبت داریم (نوعی که بیشتر اتفاق می‌افتد) اما می‌توانیم کنترل‌کننده‌های کلی را هم پوشش دهیم: ```js run function ask(question, ...handlers) { @@ -120,12 +120,12 @@ function ask(question, ...handlers) { } -// for positive answer, both handlers are called -// for negative answer, only the second one -ask("Question?", () => alert('You said yes'), result => alert(result)); +// برای جواب مثبت، هر دو کنترل‌کننده فراخوانی می‌شوند +// برای جواب منفی، فقط دومی +ask("Question?", () => alert('شما بله گفتید'), result => alert(result)); ``` -This is a particular case of so-called [polymorphism](https://en.wikipedia.org/wiki/Polymorphism_(computer_science)) -- treating arguments differently depending on their type or, in our case depending on the `length`. The idea does have a use in JavaScript libraries. +این یک مورد استفاده از [چندریختی](https://en.wikipedia.org/wiki/Polymorphism_(computer_science)) است -- رفتار متفاوت با آرگومان‌ها با توجه به نوع آنها یا در این مورد ما با توجه به `length`. این ایده در کتابخانه‌های جاوااسکریپت استفاده می‌شود. ## Custom properties From b6a2d157cab83acc58f7351d22eb20bdb757b96f Mon Sep 17 00:00:00 2001 From: MaHdi Date: Sat, 18 Sep 2021 15:25:13 +0430 Subject: [PATCH 02/10] Translate a string --- 1-js/06-advanced-functions/06-function-object/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/06-advanced-functions/06-function-object/article.md b/1-js/06-advanced-functions/06-function-object/article.md index 617a46243..10338f60e 100644 --- a/1-js/06-advanced-functions/06-function-object/article.md +++ b/1-js/06-advanced-functions/06-function-object/article.md @@ -122,7 +122,7 @@ function ask(question, ...handlers) { // برای جواب مثبت، هر دو کنترل‌کننده فراخوانی می‌شوند // برای جواب منفی، فقط دومی -ask("Question?", () => alert('شما بله گفتید'), result => alert(result)); +ask("سوال؟", () => alert('شما بله گفتید'), result => alert(result)); ``` این یک مورد استفاده از [چندریختی](https://en.wikipedia.org/wiki/Polymorphism_(computer_science)) است -- رفتار متفاوت با آرگومان‌ها با توجه به نوع آنها یا در این مورد ما با توجه به `length`. این ایده در کتابخانه‌های جاوااسکریپت استفاده می‌شود. From 49d6277c74194150d4651efd0eb3d5254aa21a0d Mon Sep 17 00:00:00 2001 From: MaHdi Date: Sun, 19 Sep 2021 22:22:20 +0430 Subject: [PATCH 03/10] Translate a part of article --- .../06-function-object/article.md | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/1-js/06-advanced-functions/06-function-object/article.md b/1-js/06-advanced-functions/06-function-object/article.md index 10338f60e..fcb18ef75 100644 --- a/1-js/06-advanced-functions/06-function-object/article.md +++ b/1-js/06-advanced-functions/06-function-object/article.md @@ -127,40 +127,40 @@ ask("سوال؟", () => alert('شما بله گفتید'), result => alert(resul این یک مورد استفاده از [چندریختی](https://en.wikipedia.org/wiki/Polymorphism_(computer_science)) است -- رفتار متفاوت با آرگومان‌ها با توجه به نوع آنها یا در این مورد ما با توجه به `length`. این ایده در کتابخانه‌های جاوااسکریپت استفاده می‌شود. -## Custom properties +## ویژگی‌های سفارشی -We can also add properties of our own. +ما می‌توانیم ویژگی‌هایی از خودمان را هم اضافه کنیم. -Here we add the `counter` property to track the total calls count: +اینجا می‌توانیم ویژگی `counter` را اضافه کنیم تا تعداد تمام فراخوانی‌ها را پیگیری کنیم: ```js run function sayHi() { - alert("Hi"); + alert("سلام"); *!* - // let's count how many times we run + // بیایید تعداد اجرا کردن را بشماریم sayHi.counter++; */!* } -sayHi.counter = 0; // initial value +sayHi.counter = 0; // مقدار اولیه -sayHi(); // Hi -sayHi(); // Hi +sayHi(); // سلام +sayHi(); // سلام -alert( `Called ${sayHi.counter} times` ); // Called 2 times +alert( `${sayHi.counter} بار فراخوانی شد` ); // دو بار فراخوانی شد ``` -```warn header="A property is not a variable" -A property assigned to a function like `sayHi.counter = 0` does *not* define a local variable `counter` inside it. In other words, a property `counter` and a variable `let counter` are two unrelated things. +```warn header="ویژگی متغیر نیست" +یک ویژگی که به یک تابع تخصیص داده شود مانند `sayHi.counter = 0`، متغیر محلی `counter` را درون آن تعریف *نمی‌کند*. به عبارتی دیگر، یک ویژگی `counter` و متغیر `let counter` دو چیز غیر مرتبط هستند. -We can treat a function as an object, store properties in it, but that has no effect on its execution. Variables never use function properties and vice versa. These are just parallel worlds. +ما می‌توانیم با یک تابع به عنوان یک شیء رفتار کنیم، ویژگی‌هایی را درون آن ذخیره کنیم اما این موضوع روی اجرا شدن آن هیچ تاثیری ندارد. متغیرها هیچوقت از ویژگی‌های تابع استفاده نمی‌کنند و برعکس. اینها فقط دنیاهای موازی هستند. ``` -Function properties can replace closures sometimes. For instance, we can rewrite the counter function example from the chapter to use a function property: +ویژگی‌های تابع می‌توانند بعضی اوقات جایگزین کلوژرها شوند. برای مثال، ما می‌توانیم مثال تابع شمارنده را از فصل بازنویسی کنیم تا از ویژگی تابع استفاده کند: ```js run function makeCounter() { - // instead of: + // :به جای این // let count = 0 function counter() { @@ -177,11 +177,11 @@ alert( counter() ); // 0 alert( counter() ); // 1 ``` -The `count` is now stored in the function directly, not in its outer Lexical Environment. +`count` حالا در به صورت مستقیم در خود تابع ذخیره شده است نه در محیط لغوی بیرونی آن. -Is it better or worse than using a closure? +این روشِ استفاده از کلوژر بهتر است یا بدتر؟ -The main difference is that if the value of `count` lives in an outer variable, then external code is unable to access it. Only nested functions may modify it. And if it's bound to a function, then such a thing is possible: +تفاوت اصلی این است که اگر مقدار `count` در یک متغیر بیرونی وجود داشته باشد، سپس کد بیرونی نمی‌تواند به آن دسترسی داشته باشد. تنها تابع‌های تودرتو ممکن است آن را تغییر دهند. و اگر فقط به یک تابع متصل باشد، سپس چنین چیزی امکان دارد: ```js run function makeCounter() { @@ -203,7 +203,7 @@ alert( counter() ); // 10 */!* ``` -So the choice of implementation depends on our aims. +پس انتخاب نحوه پیاده‌سازی به اهداف ما بستگی دارد. ## Named Function Expression From 3d755695eedf5a2bcf7fb4fbbaf5aa894e2b312f Mon Sep 17 00:00:00 2001 From: MaHdi Date: Mon, 20 Sep 2021 22:33:43 +0430 Subject: [PATCH 04/10] Translate a part of article --- .../06-function-object/article.md | 79 +++++++++---------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/1-js/06-advanced-functions/06-function-object/article.md b/1-js/06-advanced-functions/06-function-object/article.md index fcb18ef75..cdcbe3aa8 100644 --- a/1-js/06-advanced-functions/06-function-object/article.md +++ b/1-js/06-advanced-functions/06-function-object/article.md @@ -205,75 +205,74 @@ alert( counter() ); // 10 پس انتخاب نحوه پیاده‌سازی به اهداف ما بستگی دارد. -## Named Function Expression +## Function Expression نام‌گذاری شده -Named Function Expression, or NFE, is a term for Function Expressions that have a name. +Function Expression نام‌گذاری شده، یا NFE، یک عبارت برای Function Expressionهایی است که یک اسم دارند. -For instance, let's take an ordinary Function Expression: +برای مثال، بیایید یک Function Expression معمولی را فرض کنیم: ```js let sayHi = function(who) { - alert(`Hello, ${who}`); + alert(`${who} سلام،`); }; ``` -And add a name to it: +و یک اسم به آن بدهیم: ```js let sayHi = function *!*func*/!*(who) { - alert(`Hello, ${who}`); + alert(`سلام، ${who}`); }; ``` -Did we achieve anything here? What's the purpose of that additional `"func"` name? +آیا ما اینجا چیزی بدست آوردیم؟ هدف اسم اضافی `"func"` چیست؟ -First let's note, that we still have a Function Expression. Adding the name `"func"` after `function` did not make it a Function Declaration, because it is still created as a part of an assignment expression. +در ابتدا بیایید این را در نظر بگیریم که ما هنوز هم یک Function Expression داریم. اضافه کردن اسم `"func"` بعد از `function` آن را تبدیل به Function Declaration نکرد چون هنوز هم به عنوان بخشی از یک مقداردهی ساخته شده است. -Adding such a name also did not break anything. +اضافه کردن چنین اسمی چیزی را خراب نکرد. -The function is still available as `sayHi()`: +تابع هنوز هم با `sayHi()` قابل دسترس است: ```js run let sayHi = function *!*func*/!*(who) { - alert(`Hello, ${who}`); + alert(`سلام، ${who}`); }; -sayHi("John"); // Hello, John +sayHi("John"); // John ،سلام ``` -There are two special things about the name `func`, that are the reasons for it: +دو چیز خاص درباره اسم `func` وجود دارد که دلیل‌هایی برای آن داریم: -1. It allows the function to reference itself internally. -2. It is not visible outside of the function. +1. این اسم به تابع اجازه می‌دهد که به صورت درونی به خودش رجوع کند. +2. این اسم بیرون از تابع قابل رویت نیست. -For instance, the function `sayHi` below calls itself again with `"Guest"` if no `who` is provided: +برای مثال، تابع `sayHi` پایین اگر هیچ مقداری برای `who` تعیین نشود، خودش را با `"Guest"` صدا می‌زند: ```js run let sayHi = function *!*func*/!*(who) { if (who) { - alert(`Hello, ${who}`); + alert(`سلام، ${who}`); } else { *!* - func("Guest"); // use func to re-call itself + func("Guest"); // از تابع برای اینکه خودش را دوباره صدا بزند استفاده کنید */!* } }; -sayHi(); // Hello, Guest +sayHi(); // Guest ،سلام -// But this won't work: -func(); // Error, func is not defined (not visible outside of the function) +// :اما این کار نخواهد کرد +func(); // تعریف نشده است (بیرون از تابع قابل رویت نیست) func ،ارور ``` -Why do we use `func`? Maybe just use `sayHi` for the nested call? +چرا ما از `func` استفاده می‌کنیم؟ شاید فقط از `sayHi` برای فراخوانی تودرتو باید استفاده کنیم؟ - -Actually, in most cases we can: +در واقع، در اکثر موارد ما می‌توانیم این کار را انجام دهیم: ```js let sayHi = function(who) { if (who) { - alert(`Hello, ${who}`); + alert(`سلام، ${who}`); } else { *!* sayHi("Guest"); @@ -282,15 +281,15 @@ let sayHi = function(who) { }; ``` -The problem with that code is that `sayHi` may change in the outer code. If the function gets assigned to another variable instead, the code will start to give errors: +مشکل این کد، امکان تغییر `sayHi` در کد بیرونی است. اگر تابع به یک متغیر دیگر تخصیص داده شود، کد شروع به ایجاد ارور می‌کند: ```js run let sayHi = function(who) { if (who) { - alert(`Hello, ${who}`); + alert(`سلام، ${who}`); } else { *!* - sayHi("Guest"); // Error: sayHi is not a function + sayHi("Guest"); // تابع نیست sayHi :ارور */!* } }; @@ -298,22 +297,22 @@ let sayHi = function(who) { let welcome = sayHi; sayHi = null; -welcome(); // Error, the nested sayHi call doesn't work any more! +welcome(); // !دیگر کار نمی‌کند sayHi ارور، فراخوانی تودرتوی ``` -That happens because the function takes `sayHi` from its outer lexical environment. There's no local `sayHi`, so the outer variable is used. And at the moment of the call that outer `sayHi` is `null`. +دلیل بروز ارور این است که تابع `sayHi` را از محیط لغوی بیرونی دریافت می‌کند. هیچ `sayHi` محلی وجود ندارد پس متغیر بیرونی استفاده می‌شود. و در زمان فراخوانی `sayHi` بیرونی برابر با `null` است. -The optional name which we can put into the Function Expression is meant to solve exactly these kinds of problems. +اسم اختیاری که ما می‌توانیم در Function Expression قرار می‌دهیم قرار است که دقیقا این دسته از مشکلات را حل کند. -Let's use it to fix our code: +بیایید از آن برای رفع مشکل کد خود استفاده کنیم: ```js run let sayHi = function *!*func*/!*(who) { if (who) { - alert(`Hello, ${who}`); + alert(`سلام، ${who}`); } else { *!* - func("Guest"); // Now all fine + func("Guest"); // حالا همه چیز درست است */!* } }; @@ -321,17 +320,17 @@ let sayHi = function *!*func*/!*(who) { let welcome = sayHi; sayHi = null; -welcome(); // Hello, Guest (nested call works) +welcome(); // (فراخوانی تودرتو کار می‌کند) Guest ،سلام ``` -Now it works, because the name `"func"` is function-local. It is not taken from outside (and not visible there). The specification guarantees that it will always reference the current function. +حالا کار می‌کند چون اسم `"func"` یک تابع محلی است. این اسم از بیرون دریافت نمی‌شود (و آنجا هم قابل رویت نیست). مشخصات زبان تضمین می‌کند که این اسم همیشه به تابع کنونی رجوع می‌کند. -The outer code still has its variable `sayHi` or `welcome`. And `func` is an "internal function name", how the function can call itself internally. +کد بیرونی هنوز هم متغیر `sayHi` یا `welcome` خود را دارد. و `func` یک «اسم تابع درونی» است، جوری که تابع می‌توانند از درون خودش را فراخوانی کند. -```smart header="There's no such thing for Function Declaration" -The "internal name" feature described here is only available for Function Expressions, not for Function Declarations. For Function Declarations, there is no syntax for adding an "internal" name. +```smart header="چنین چیزی برای Function Declaration وجود ندارد" +خصوصیت «اسم درونی» که اینجا توضیح داده شد فقط برای Function Expessionها قابل استفاده است نه برای Function Declarationها. برای Function Declarationها، سینتکسی برای اضاف کردن اسم «درونی» وجود ندارد. -Sometimes, when we need a reliable internal name, it's the reason to rewrite a Function Declaration to Named Function Expression form. +بعضی‌اوقات، نیاز به یک اسم درونی قابل، دلیلی برای نوشتن دوباره‌ی یک Function Declaration به Function Expression نام‌گذاری‌شده است. ``` ## Summary From aeb47e201353fce8768e5e0fe1529f01e14f8ec9 Mon Sep 17 00:00:00 2001 From: MaHdi Date: Tue, 21 Sep 2021 21:16:01 +0430 Subject: [PATCH 05/10] Translate article --- .../06-function-object/article.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/1-js/06-advanced-functions/06-function-object/article.md b/1-js/06-advanced-functions/06-function-object/article.md index cdcbe3aa8..540dc7346 100644 --- a/1-js/06-advanced-functions/06-function-object/article.md +++ b/1-js/06-advanced-functions/06-function-object/article.md @@ -333,20 +333,20 @@ welcome(); // (فراخوانی تودرتو کار می‌کند) Guest ،سل بعضی‌اوقات، نیاز به یک اسم درونی قابل، دلیلی برای نوشتن دوباره‌ی یک Function Declaration به Function Expression نام‌گذاری‌شده است. ``` -## Summary +## خلاصه -Functions are objects. +تابع‌ها شیء هستند. -Here we covered their properties: +اینجا ما ویژگی‌های آنها را پوشش دادیم: -- `name` -- the function name. Exists not only when given in the function definition, but also for assignments and object properties. -- `length` -- the number of arguments in the function definition. Rest parameters are not counted. +- `name` -- اسم تابع. نه تنها در تعریف یک تابع وجود دارد، بلکه در مقداردهی‌ها و ویژگی‌های شیء هم موجود است. +- `length` -- تعداد آرگومان‌ها در تعریف تابع. پارامترهای رست شمرده نمی‌شوند. -If the function is declared as a Function Expression (not in the main code flow), and it carries the name, then it is called a Named Function Expression. The name can be used inside to reference itself, for recursive calls or such. +اگر تابعی به عنوان Function Expression تعریف شود (نه در جریان اصلی کد)، و اسمی داشته باشد، سپس به آن یک Function Expression نام‌گذاری شده می‌گویند. اسم می‌تواند درون آن برای رجوع به خودش استفاده شود، مثلا برای فراخوانی‌های بازگشتی یا چنین چیزی. -Also, functions may carry additional properties. Many well-known JavaScript libraries make great use of this feature. +همچنین، تابع‌ها ممکن است ویژگی‌های اضافی هم داشته باشند. تعداد زیادی از کتابخانه‌های شناخته‌شده‌ی جاوااسکریپت از این خاصیت خیلی استفاده می‌کنند. -They create a "main" function and attach many other "helper" functions to it. For instance, the [jQuery](https://jquery.com) library creates a function named `$`. The [lodash](https://lodash.com) library creates a function `_`, and then adds `_.clone`, `_.keyBy` and other properties to it (see the [docs](https://lodash.com/docs) when you want to learn more about them). Actually, they do it to lessen their pollution of the global space, so that a single library gives only one global variable. That reduces the possibility of naming conflicts. +آنها یک تابع «اصلی» می‌سازند و تعداد زیادی از تابع‍‌های «کمکی» را به آن متصل می‌کنند. برای مثال، کتابخانه [jQuery](https://jquery.com) یک تابع به نام `$` می‌سازد. کتابخانه [lodash](https://lodash.com) یک تابع `_` می‌سازد و سپس ویژگی‌های `_.clone`، `_keyBy` و بقیه ویژگی‌ها را به آن اضافه می‌کند (زمانی که می‌خواهید درباره آنها بیشتر بدانید، [مستندات](https://lodash.com/docs) را ببینید). در واقع، آنها این کار را برای کاهش آلودگی فضای گلوبال انجام می‌دهند تا یک کتابخانه فقط یک متغیر گلوبال داشته باشد. این باعث کاهش احتمال وقوع تناقض در نام‌گذاری می‌شود. -So, a function can do a useful job by itself and also carry a bunch of other functionality in properties. +پس یک تابع، می‌تواند توسط خودش یک کار مفید انجام دهد و همچنین چند عملکرد مختلف را در ویژگی‌هایش داشته باشد. From 15f953fc8d5e32539ab0df3f9ee556ba05aa4569 Mon Sep 17 00:00:00 2001 From: MaHdi Date: Tue, 21 Sep 2021 22:01:25 +0430 Subject: [PATCH 06/10] Translate task of "counter-inc-dec" --- .../06-function-object/2-counter-inc-dec/task.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md index a11821d67..15ecb1b63 100644 --- a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md +++ b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md @@ -2,14 +2,14 @@ importance: 5 --- -# Set and decrease for counter +# تنظیم و کم کردن برای شمارنده -Modify the code of `makeCounter()` so that the counter can also decrease and set the number: +کد `makeCounter()` را طوری تغییر دهید که شمارنده بتواند هم عدد را تنظیم کند و هم آن را کاهش دهد: -- `counter()` should return the next number (as before). -- `counter.set(value)` should set the counter to `value`. -- `counter.decrease()` should decrease the counter by 1. +- `counter()` باید عدد بعدی را برگرداند (مانند قبل). +- `counter.set(value)` باید شمارنده را در `value` تنظیم کند. +- `counter.decrease()` باید از شمارنده به اندازه 1 کم کند. -See the sandbox code for the complete usage example. +برای دیدن مثالی کامل از نحوه استفاده، کد محیط ایزوله ببینید. -P.S. You can use either a closure or the function property to keep the current count. Or write both variants. +پی‌نوشت: شما می‌توانید از کلوژر یا ویژگی تابع برای حفظ کردن شماره کنونی استفاده کنید. یا هر دو نوع را بنویسید. From 32ca021f7089ebbfb73396a8ec8345501b34ac03 Mon Sep 17 00:00:00 2001 From: MaHdi Date: Tue, 21 Sep 2021 22:03:23 +0430 Subject: [PATCH 07/10] Translate solution of "counter-inc-dec" --- .../06-function-object/2-counter-inc-dec/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/solution.md b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/solution.md index e829d96ee..603fa0369 100644 --- a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/solution.md +++ b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/solution.md @@ -1,2 +1,2 @@ -The solution uses `count` in the local variable, but addition methods are written right into the `counter`. They share the same outer lexical environment and also can access the current `count`. +راه‌حل از `count` در متغیر محلی استفاده می‌کند اما متدهای اضافی درست درون `counter` نوشته شده‌اند. آنها محیط لغوی بیرونی یکسان را به اشتراک می‌گذارند و همچنین می‌توانند به `count` کنونی دسترسی پیدا کنند. From 3facf6be68487c95c1275c99849bc8df975dd299 Mon Sep 17 00:00:00 2001 From: MaHdi Date: Tue, 21 Sep 2021 22:06:52 +0430 Subject: [PATCH 08/10] Translate task of "sum-many-brackets" --- .../06-function-object/5-sum-many-brackets/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/task.md b/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/task.md index dc13f260b..319dcd26f 100644 --- a/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/task.md +++ b/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/task.md @@ -2,9 +2,9 @@ importance: 2 --- -# Sum with an arbitrary amount of brackets +# جمع زدن با تعداد دلخواهی از پرانتز -Write function `sum` that would work like this: +تابع `sum` را بنویسید که اینگونه کار کند: ```js sum(1)(2) == 3; // 1 + 2 @@ -14,4 +14,4 @@ sum(6)(-1)(-2)(-3) == 0 sum(0)(1)(2)(3)(4)(5) == 15 ``` -P.S. Hint: you may need to setup custom object to primitive conversion for your function. \ No newline at end of file +پی‌نوشت: راهنمایی: شما ممکن است نیاز داشته باشید که تبدیل شیء به مقدار اصلی سفارشی برای تابع خود بنویسید. From 852194d22aa07156d9dff4f1983907d051aa6986 Mon Sep 17 00:00:00 2001 From: MaHdi Date: Tue, 21 Sep 2021 22:20:13 +0430 Subject: [PATCH 09/10] Translate solution of "sum-many-brackets" --- .../5-sum-many-brackets/solution.md | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md b/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md index e97039f72..120f6add3 100644 --- a/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md +++ b/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md @@ -1,9 +1,9 @@ -1. For the whole thing to work *anyhow*, the result of `sum` must be function. -2. That function must keep in memory the current value between calls. -3. According to the task, the function must become the number when used in `==`. Functions are objects, so the conversion happens as described in the chapter , and we can provide our own method that returns the number. +1. برای اینکه همه چیز به *هر نحوی* کار کند، نتیجه `sum` باید تابع باشد. +2. آن تابع باید بین فراخوانی‌ها مقدار کنونی را در حافظه ذخیره کند. +3. با توجه به تمرین، تابع باید زمانی که با `==` استفاده می‌شود، تبدیل به عدد شود. تابع‌ها شیء هستند پس تبدیل شدن همانطور که در فصل گفته شد اتفاق می‌افتد و ما می‌توانیم متد خودمان را برای برگرداندن عدد بسازیم. -Now the code: +حالا می‌رسیم به کد: ```js demo run function sum(a) { @@ -28,28 +28,28 @@ alert( sum(6)(-1)(-2)(-3) ); // 0 alert( sum(0)(1)(2)(3)(4)(5) ); // 15 ``` -Please note that the `sum` function actually works only once. It returns function `f`. +لطفا در نظر داشته باشید که تابع `sum` فقط یکبار کار می‌کند. تابع `f` را برمی‌گرداند. -Then, on each subsequent call, `f` adds its parameter to the sum `currentSum`, and returns itself. +سپس در هر فراخوانی زیر مجموعه آن، تابع `f` پارامتر خودش را به جمع `currentSum` اضافه می‌کند و خودش را برمی‌گرداند. -**There is no recursion in the last line of `f`.** +**هیچ بازگشتی در آخرین خط `f` وجود ندارد.** -Here is what recursion looks like: +بازگشتی اینگونه بنظر می‌رسد: ```js function f(b) { currentSum += b; - return f(); // <-- recursive call + return f(); // <-- فراخوانی بازگشتی } ``` -And in our case, we just return the function, without calling it: +و در این مورد ما، بدون صدا زدن تابع، ما فقط آن را برمی‌گردانیم: ```js function f(b) { currentSum += b; - return f; // <-- does not call itself, returns itself + return f; // <-- خودش را صدا نمی‌زد، خودش را برمی‌گرداند } ``` -This `f` will be used in the next call, again return itself, as many times as needed. Then, when used as a number or a string -- the `toString` returns the `currentSum`. We could also use `Symbol.toPrimitive` or `valueOf` here for the conversion. +این `f` در فراخوانی بعدی استفاده می‌شود و دوباره خودش را برمی‌گرداند، هر چند باری که نیاز باشد. سپس زمانی که به عنوان یک عدد یا رشته استفاده می‌شود -- `toString` مقدار `currentSum` را برمی‌گرداند. ما می‌توانستیم برای تبدیل از `Symbol.toPrimitive` یا `valueOf` اینجا استفاده کنیم. From 9c836775a3c0eca57f2144844c1fd000eeb84105 Mon Sep 17 00:00:00 2001 From: MaHdi Date: Wed, 22 Sep 2021 07:43:03 +0330 Subject: [PATCH 10/10] Update 1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md Co-authored-by: Mahdyar Hasanpour --- .../06-function-object/2-counter-inc-dec/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md index 15ecb1b63..73bc6c3eb 100644 --- a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md +++ b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md @@ -10,6 +10,6 @@ importance: 5 - `counter.set(value)` باید شمارنده را در `value` تنظیم کند. - `counter.decrease()` باید از شمارنده به اندازه 1 کم کند. -برای دیدن مثالی کامل از نحوه استفاده، کد محیط ایزوله ببینید. +برای دیدن مثالی کامل از نحوه استفاده، کد جعبهٔ شنی(sandbox) را ببینید. پی‌نوشت: شما می‌توانید از کلوژر یا ویژگی تابع برای حفظ کردن شماره کنونی استفاده کنید. یا هر دو نوع را بنویسید.