Introduction To Functions Going Deeper With Primitive and Objects
Introduction To Functions Going Deeper With Primitive and Objects
Introduction to Functions
Function as an expression itself
تعتب
تعيد قيمة ==< القيمة المرجعة رfunction يف حال كانت ال-
معقدة أ كبexpression ويمكن دمجها ضمنexpression
: مثال-
- Function x(){return `test`}
- Console.log(`this is ${x()}`) ➔ "this is test"
- Console.log (typeof (x())); ➔ "string"
- Console.log (typeof(x)); ➔ function (built-in object)
ه
نفسها يfunction فإن ال، ال تعيد قيمةfunctions يف حال ال-
ليسfunction لكن القيمة النهائية لل،expression (object)
وف حال جربنا سبى أنه ال يمكن أن
ي،statement بل، expression
أكب تعقيداexpressions نضعها ضمن
: مثال-
- Function x(){console.log(`test`)}
- Console.log(`this is ${x()}`) ➔ "this is undefined"
- Console.log(typeof(x())) ➔ undefined
- Console.log(typeof (x)) ➔ function (built-in object)
-
Anonymous Function
- Function (){}
- Function x(){};
Arrow function
- object values are all first class objects, which means that we
can assign the objects to variable, sending it as argument, and
return it from functions.
Const p1 = {
"name": "karim",
"sayhello": function(){
Console.log(`hello world`);
}
Console.log(typeof(p1))➔ object
ه
العادية يfunction أساسا ال، العاديةfunction أساسا هو بينعمل بال-
أو نستعمال مشان،بيصب اذا بدنا نستدعيها
ر بس،constructer بحد ذاتا
بينماobjects الل بينعملو فيها هن يobject ال،instances نضيف
built-in object ه بذاتا يfunctionال
- function Person(firstName, lastName, age) {
-
- console.log(firstName + lastName + age)
-
- }
-
- console.log(typeof(Person)) ➔ function;
-
- let p1 = new Person1S(`test`,`test`,10);
- console.log(typeof(p1)) ➔ object (even if its not really object
within the oop terminology but all functions (and other built-in
objects are constructers));
another example:
function Person(name){
this.name = name
//methods
console.log(this.name)
}
2- Built-in objects/native objects (are actually built-in
functions):
typeof لكن عند محاولة معرفة نوعها باستعمال،يؤدي إلى إنشاء مصفوفة
object سنحصل على
:أمثلة
1- Function Person(){
This.person = `karim`
Console.log(typeof(Person)) ➔ function
Console.log(typeof(p1)) ➔ object
Console.log(typeof(arr)) ➔ object
Console.log(typeof(arr.constructer)) ➔ function
Console.log(typeof(Array)) ➔ function
Going deeper with primitive and objects, with تلخيص
expressions and statements
(أو حتىnew لكن عند التحقق من المصفوفة التي تقوم بإنشائها باستخدام
object ) فهي ستكونliteral
فإنها تقومnew التي تقوم عند استعمالfunction Person مثال آخر هو
Person من النوعobject بإنشاء