-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctionsAsObject.js
29 lines (22 loc) · 955 Bytes
/
functionsAsObject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//function is itself a object. It has properties and methods.
console.log("function acts as object in javascript.");
function Circle(arg){
this.radius=arg;
console.log("method's parameter: ", arg);
}
console.log("Let's print some of the properties of a function.")
console.log("Circle method's arguments property: ",Circle.arguments)
console.log("Function name: ", Circle.name);
// f Function() is built in constructor which is used to create javascript function.
// We can assume a function is like this:
const Circle1 = new Function('arg',`
this.radius= arg;
console.log("method's parameter: ", arg);
`);
console.log("Function name: ", Circle1.name);
const obj = new Circle1(1);
//Let's explore some other methods of a function object:
const obj1 = Circle.call({},10);
const ob2 = new Circle(20);
//here obj1 and obj2 is perfectly similar. The new keyword at first creates
// en empty object {} and pass that into call method.