Topic 12: OOPs: creating object templates & objects: way 3 - with Object.create() method

//Regular Lecture 20: 19 Oct 2022

//Topic 12: //* oops- object oriented programming*// creating object templates // way 3


//3) with Object.create()


//example 1

//create template:

let form11 = {
    init:function(fn,ln,ag){
        this.firstName = fn
        this.lastName = ln
        this.age = ag 
        // this.display = function(){
        //     console.log(this.firstName + this.lastName)
        }
    // }
}


//now create object:

let amol5 = Object.create(form11)
console.log(amol5)
amol5.init("amol5","rao5",34)
console.log(amol5)


//example 2

let form12 = {
    init:function(fn, ln, ag){
        this.firstName = fn
        this.lastName = ln
        this.age = ag
    }
}

let umesh = Object.create(form12)
umesh.init("umesh", "yadav", 34)
console.log(umesh)

let ravi = Object.create(form12)
ravi.init("ravi", "ashwin", 36)
console.log(ravi)


//example 3

let form13 = {
    init:function(ful, c, s, cn){
        this.fullName = ful
        this.city = c
        this.state = s
        this.country = cn
    }
}

let priyanka = Object.create(form13)
priyanka.init("priyanka gandhi", "delhi", "UP", "India")
console.log(priyanka)

let supriya = Object.create(form13)
supriya.init("supriya sule", "pune", "MH", "India")
console.log(supriya)

टिप्पण्या