Skip to content

Instantly share code, notes, and snippets.

@royib
royib / hadBindingArrow.js
Created April 1, 2024 18:24
this article- hard binding with arrow function
function car(manufacture, model){
this.manufacture = manufacture;
this.model = model
this.print = () => {
console.log(this.manufacture + " " + this.model)
}
}
var toyotaObj = new car("Toyota", "Camry");
@royib
royib / hardBinding.js
Created April 1, 2024 18:17
this article- hard binding
function car(manufacture, model){
this.manufacture = manufacture;
this.model = model
this.print = function() {
console.log(this.manufacture + " " + this.model)
}
}
var toyotaObj = new car("Toyota", "Camry");
@royib
royib / dynamicSimpleObject.js
Last active April 1, 2024 18:09
this Article - dynamic object
function car(manufacture, model){
this.manufacture = manufacture;
this.model = model
this.print = () => {
console.log(this.manufacture + " " + this.model)
}
}
var toyotaObj = new car("Toyota", "Camry");
toyotaObj.print(); // Toyota Camry
@royib
royib / dynamicNew.js
Last active March 26, 2024 07:33
this Article - dynamic new
let bar= "bar";
function foo(){
this.baz = "baz";
console.log(bar + " " + this.baz);
}
var obj = new foo(); // bar baz
@royib
royib / dynamicUndefined.js
Last active March 26, 2024 07:18
this Article - dynamic undefined
function foo()
{
let bar = "hello";
console.log(this.bar);
}
foo() // undefined
@royib
royib / lexicalScope.js
Last active April 1, 2024 18:52
this Article - Lexical scope
function bar() {
let foo = "bar";
bam = "yay";
}
bar();
console.log(bam); //output yay
console.log(foo); //ReferenceError: foo is not defined
@royib
royib / classInheritance.js
Last active March 2, 2024 16:53
Class Article - inheritance using classes
// Person class
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
getName() {
return `person name is: ${this.firstName} ${this.lastName}`;
}
@royib
royib / inheritance.js
Last active March 2, 2024 15:19
Class article - inheritance
// Person constructor function
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
// Add function to the Person prototype
Person.prototype.getName = function() {
return `person name is: ${this.firstName} ${this.lastName}`;
}
@royib
royib / prototype_chain.js
Last active March 2, 2024 16:55
Class article - prototype chain
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.getName = function() {
return `person name is: ${this.firstName} ${this.lastName}`;
}
// Creating a new instance of Person
@royib
royib / SimpleObject.js
Last active February 29, 2024 06:47
Class article - Simple Object
let Person = {
firstName: "john",
lastName: "duo"
}