Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //javascript 'this', call bind apply
- //"this"
- //global execution context
- //functional execution context
- // const a = 10
- // function sum(num1, num2) {
- // return num1 + num2
- // }
- // console.log(sum(10, 15))
- // console.log(a)
- //in global execution context - window
- // In functional execution context
- //- plain function call - window, undefined(in strict mode)
- //- with object chaining- that object
- // inside constructor function - empty object
- //in strict mode (plain function call) - undefined
- // console.log(this) // window
- // function greet() {
- // console.log(this) //window
- // return 'Hi'
- // }
- // //how you call the function
- // //plain way - window
- // greet()
- // const person = {
- // firstName: 'samim',
- // lastName: 'Fazlu',
- // fullName() {
- // console.log(this)
- // // const $that = this
- // // function inner() {
- // // console.log($that)
- // // return $that.firstName + ' ' + $that.lastName
- // // }
- // //arrow function has no this binding
- // const inner = () => {
- // return this.firstName + ' ' + this.lastName
- // }
- // console.log(inner())
- // },
- // }
- // person.fullName()
- // const fullName = person.fullName
- // console.log(fullName.call(person))
- // function Person(){
- // //this = {}
- // this.fName = 'samim'
- // console.log(this)
- // }
- // const samim = new Person()
- // console.log(samim)
- // function greet(lName, age) {
- // return 'Hi' + ' ' + this.name + ' ' + lName + '-' + age
- // }
- // //you can define 'this'
- // const person = { name: 'samim' }
- // // const obj = greet.call(person, 'Hasan', 30)
- // // const obj = greet.apply(person, ['Hasan', 30])
- // //work like call , function is not called
- // const boundFunc = greet.bind(person, 'Hasan', 30)
- // //this can't be changed (after bind once)
- // console.log(boundFunc())
- //first class function
- //function(value) can be used as any data type
- //functions can be assigned to any other variable or passed as an argument or can be returned by another function
- // A “higher-order function” is a function that accepts functions as parameters and/or returns a function.
- //greet -higher order function
- //func - callback function
- // const greet = (fn) => {
- // fn('Hi')
- // // console.log('Hi')
- // }
- // const func = function (initial) {
- // console.log(initial + ' ' + 'world')
- // }
- // console.log(
- // greet(func)
- // )
- //Higher order function
- //lambda function (innerFunc)
- function sum(num1) {
- return (num2) => {
- return num1 + num2
- }
- }
- // const secondFunc = sum(3)
- // console.log(secondFunc)
- // console.log(secondFunc(2) )
- // console.log(sum(3)(2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement