This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function User (firstName, lastName) { | |
| this.first_Name = firstName | |
| this.last_Name = lastName | |
| } | |
| const showUserDetails = new User('akash', 'rajvanshi') | |
| console.log(showUserDetails) // User { first_Name: 'akash', last_Name: 'rajvanshi' } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function showDetails() { | |
| console.log(`My Name is ${this.fullName}`) // My Name is undefined | |
| } | |
| const User = { | |
| fullName: 'Akash Rajvanshi' | |
| } | |
| //call without any .call()/ .apply()/ .bind() | |
| showDetails() | |
| //As we know in simple function "this" refer to the window object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var name = { | |
| firstName: 'Akash' | |
| } | |
| function showDetails(lastName, age) { | |
| console.log(this.firstName + ' ' + lastName + ' : ' + age) // Akash Rajvanshi : 22 | |
| } | |
| showDetails.apply(name, ['Rajvanshi', 22]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Person(firstName, lastName) { | |
| this.first_name = firstName | |
| this.last_name = lastName | |
| this.showDetails = function () { | |
| console.log(`Name: ${this.first_name} ${this.last_name}`) // Name: Akash Rajvanshi | |
| } | |
| } | |
| const person = new Person('Akash', 'Rajvanshi') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var name = { | |
| firstName: 'Akash' | |
| } | |
| function showDetails(lastName, age) { | |
| console.log(this.firstName + ' ' + lastName + ' : ' + age) // Akash Rajvanshi : 22 | |
| } | |
| showDetails.call(name, 'Rajvanshi', 22) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function showDetails() { | |
| console.log(this) // { firstName: 'Akash', lastName: 'Rajvanshi' } X 3 | |
| console.log(this.firstName, this.lastName) // Akash Rajvanshi x 3 | |
| } | |
| var fullName = { | |
| firstName: 'Akash', | |
| lastName: 'Rajvanshi' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const button = document.querySelector('button') | |
| button.addEventListener('click', e => { | |
| console.log(this) // window | |
| console.log(e.currentTarget) // button | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example ssh config file. Usually located in ~/.ssh/config (user) or /etc/ssh/ssh_config (system) | |
| # This works on both linux and MacOS | |
| # Basic ssh commands converted to ssh/config file format | |
| # Simplest format | |
| # Run with: "ssh blog" => (equivalent to: "ssh ubuntu@example.com" and "ssh -i ~/.ssh/id_rsa -p 22 ubuntu@example.com") | |
| Host blog |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Example of Single object | |
| const user = { | |
| firstName: 'Akash', | |
| lastName: 'Rajvanshi', | |
| age: 22, | |
| getDetails() { | |
| console.log(`I am ${this.firstName} ${this.lastName}`) | |
| } | |
| } | |
| user.getDetails() // I am Akash Rajvanshi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Example Of Constructor Function | |
| function User(firstName, lastName, age) { | |
| this.firstName = firstName | |
| this.lastName = lastName | |
| this.age = age | |
| this.getDetails = function () { | |
| console.log(`I am ${this.firstName} ${this.lastName}`) | |
| } | |
| } |