Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //part 1
- //create an object
- // const user = {}
- // user.name = "shopnil"
- // user.age = 25
- // user.intro = function () {
- // console.log(`I am ${user.name} I am ${user.age} years old`);
- // }
- // // console.log(user);
- // user.intro()
- //part 2
- //create a constructor function object
- // function User (name, age) {
- // const user = {}
- // user.name = name
- // user.age = age
- // user.intro = function () {
- // console.log(`I am ${user.name} I am ${user.age} years old`);
- // }
- // return user
- // }
- // const shopnil = User("shopnil", 25)
- // shopnil.intro()
- //part 3
- //create a constructor function object
- // const userMethod = {
- // intro (user) {
- // console.log(`I am ${user.name} I am ${user.age} years old`);
- // }
- // }
- // function User (name, age) {
- // const user = {}
- // user.name = name
- // user.age = age
- // user.intro = userMethod.intro.bind(user, user)
- // return user
- // }
- // const shopnil = User("shopnil", 25)
- // const sidrat = User("sidrat", 18)
- // // console.log(shopnil);
- // shopnil.intro()
- // console.dir(shopnil)
- // console.dir(sidrat)
- //part 4
- //create a constructor function but the method store as a prototype
- // const userMethod = {
- // intro (user) {
- // console.log(`I am ${user.name} I am ${user.age} years old`);
- // }
- // }
- // function User (name, age) {
- // const user = Object.create(userMethod)
- // user.name = name
- // user.age = age
- // return user
- // }
- // const shopnil = User("shopnil", 25)
- // const sidrat = User("sidrat", 18)
- // // console.log(shopnil);
- // shopnil.intro(shopnil)
- // console.dir(shopnil)
- // console.dir(sidrat)
- //part 5
- //store the outer method function into function's prototype method or property
- // function User (name, age) {
- // const user = Object.create(User.prototype )
- // user.name = name
- // user.age = age
- // return user
- // }
- // User.prototype = {
- // intro (user) {
- // console.log(`I am ${user.name} I am ${user.age} years old`);
- // }
- // }
- // const shopnil = User("shopnil", 25)
- // const sidrat = User("sidrat", 18)
- // // console.log(shopnil);
- // shopnil.intro(shopnil)
- // console.dir(shopnil)
- // console.dir(sidrat)
- //part 6
- //create a constructor function but the method store as a prototype
- // const userMethod = {
- // intro (user) {
- // console.log(`I am ${user.name} I am ${user.age} years old`);
- // }
- // }
- // function User (name, age) {
- // const user = Object.create(userMethod)
- // user.name = name
- // user.age = age
- // return user
- // }
- // const shopnil = User("shopnil", 25)
- // const sidrat = User("sidrat", 18)
- // // console.log(shopnil);
- // shopnil.intro(shopnil)
- // console.dir(shopnil)
- // console.dir(sidrat)
- //part 5
- // store the outer method function into function's prototype method or property and create the contractor function with new keyword
- // function User (name, age) {
- // // const user = Object.create(User.prototype )
- // this.name = name
- // this.age = age
- // // return user
- // }
- // User.prototype = {
- // intro (user) {
- // console.log(`I am ${user.name} I am ${user.age} years old`);
- // }
- // }
- // const shopnil = new User("shopnil", 25)
- // const sidrat = new User("sidrat", 18)
- // // console.log(shopnil);
- // shopnil.intro(shopnil)
- // console.dir(shopnil)
- // // console.dir(sidrat)
- //part 6
- //make a contractor function with method with the help of prototype in vanila java script way
- // function User (name, age) {
- // this.name = name
- // this.age = age
- // }
- // User.prototype = {
- // intro (user) {
- // console.log(`I am ${user.name} I am ${user.age} years old`);
- // }
- // }
- // const shopnil = new User("shopnil", 25)
- // const sidrat = new User("sidrat", 18)
- // shopnil.intro(shopnil)
- // console.dir(User)
- //make a contractor with method with the help of new es6 class syntax way
- // class User {
- // constructor (name, age) {
- // this.name = name
- // this.age = age
- // }
- // intro (user) {
- // console.log(`I am ${user.name} I am ${user.age} years old`);
- // }
- // }
- // const shopnil = new User("shopnil", 25)
- // const sidrat = new User("sidrat", 18)
- // shopnil.intro(shopnil)
- // console.dir(shopnil)
- //Create a class constructor with method from the scratch part 1 - part 6
- //Start the inheritance part with vanila js way first
- // Part 7
- //create the inheritance with vanila javascript way
- //Parent
- // function Parent (name, age) {
- // this.name = name
- // this.age = age
- // }
- // Parent.prototype = {
- // intro: function(){
- // console.log(`Hello I am ${this.name} I am ${this.age} years old`);
- // }
- // }
- // //Child one
- // function Child (name, age, birthDate) {
- // Parent.call(this, name, age)
- // this.birthDate = birthDate
- // }
- // Child.prototype = Object.create(Parent.prototype)
- // Child.prototype.constructor = Child
- // Child.prototype.hello = function () {
- // console.log(`hello`);
- // }
- // //Grand Child
- // function GrandChild (name, age, birthDate) {
- // Child.call(this, name, age, birthDate)
- // }
- // GrandChild.prototype = Object.create(Child.prototype)
- // GrandChild.prototype.constructor = GrandChild
- // const childThree = new GrandChild("sidrat", 14, "1999-05-20")
- // childThree.intro()
- // Part 8
- //Create the inheritance with class
- class Parent {
- constructor (name, age) {
- this.name = name
- this.age = age
- }
- intro(){
- console.log(`Hello I am ${this.name} I am ${this.age} years old`);
- }
- }
- //Child
- class Child extends Parent {
- constructor (name, age, birthDate) {
- super (name, age)
- this.birthDate = birthDate
- }
- hello () {
- console.log(`hello`);
- }
- }
- const childOne = new Child ("ridon", 23, "1999-05-25")
- console.log(childOne);
- //GrandChild
- class GrandChild extends Child {
- constructor (name, age, birthDate) {
- super (name, age, birthDate)
- }
- }
- const grandChildOne = new GrandChild ("sakib", 23, "1999-05-25")
- console.log(grandChildOne);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement