Skip to content

Instantly share code, notes, and snippets.

@debugmodedotnet
Created June 19, 2021 12:01
Show Gist options
  • Save debugmodedotnet/90e55c33b2a804514c05539c6854642b to your computer and use it in GitHub Desktop.
Save debugmodedotnet/90e55c33b2a804514c05539c6854642b to your computer and use it in GitHub Desktop.
function Product(title,price){
this.title = title;
this.price = price;
console.log(this);
}
// call a function as method - MIP
// value of this inside function - always object before dot
// var Foo = {
// name :"DJ",
// Product:function(title,price){
// console.log(this);
// }
// }
// var Koo = {
// title:'koo',
// age : 9
// }
// Foo.Product();
// // call a function as function - FIP
// // value of this inside function - global object
// var p1 = Product("Pen",20);
// console.log(p1);
// // call a function as constructor - CIP
// // value of this inside function - always newly created object
// // [[Construct]]
// var p1 = new Product("Pen",20);
// console.log(p1);
function sendEmail(message,to){
this.message = message;
this.to = to;
console.log(this);
}
var Manger = {
name :'foo',
sal : 489494
};
var Employee = {
name :'koo',
managername :'foo',
sale : 3477
}
// IIP , you can pass value of this manually
// ABC
// apply - array
// bind - new object
// call - commas
sendEmail.apply(Manger,["Hello how are you",'debugmode@outlook.com']);
sendEmail.call(Employee,"Hello emp how are you",'hello@geek97.com');
var Product = (title,price)=>{
}
// arrow function does not have its own valuwe of 'this'
// arrow function can not be used with new . means you can not use it CIP because it does not have
// [[Construct]]
// arrow functioon does not have arguments object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment