Java script Prototyping: JavaScript is a object oriented programming. Object’s are foundational to the JavaScript programming language. Learning how to declare and define objects and function is one of the first thing’s to be learnt. Learn these properties first before moving on to other topics.
We can’t learn java script without learning objects. Objects are key/value pairs. Curly braces {} is the common way for declaring an object and use dot notation for adding properties and methods to an object. We have created SEO encapsulated inside a function that we call when we want to add a project. Constructor function and Functional Instantiation with Shared Methods are two ways of declaring an objects. Teerthanker Mahaveer University [TMU], Moradabad Uttar Pradesh is well known for its coding culture. Teerthanker Mahaveer University, Moradabad got direct campus placements in top companies like Infosys, Wipro, TCS, IBM, HDFC Bank and more.
const SEOmethord = {
On-page(Meta) {
console.log(`${title} is most important.`)
},
Off-page(Backlinks) {
console.log(`${article sharing} is worthy.`)
},
Technical() {
console.log(`${technical changes} is needed.`)
}
}
function SEO (project name) {
let project = {}
project.name = name
project.cost = cost
project.On-page = SEOmethod.On-page
project.Off-page = SEOmethod.Off-page
project.Technical = SEOmethod.Technical
return project
}
We'll need to create more than one SEO project’s. The next step must be to include logic inside of a function that can be called just by creating a project. We call this way as Functional Instantiation and also known as "constructor function" since it's for creating a object.
Functional Instantiation
function SEO (name, cost) {
let SEO = {}
SEO.name = name
SEO.cost= cost
SEO.On page = function (meta) {
console.log(`${title} is most important.`)
}
SEO.Off page = function (backlinks) {
console.log(`${article sharing} is worthy.`)
}
SEO.Technical = function () {
console.log(`${technical changes} is needed.`)
}
return SEO
}
Now whenever we want to add a a new instance, then all we have to do is to call the function, passing the SEO’s name. This works great and is incredibly simple. This is wastage of memory when we create SEO objects bigger than it needed to be. Rethink about the solution Rather than re-creating these methods every time we invoke these functions a new project name gets created, This pattern is a Functional Instantiation with Shared Methods.
Functional Instantiation with Shared Methods
const SEOMethods = {
On-page(meta) {
console.log(`${title} is most important.`)
},
Off-page(backlink) {
console.log(`${article sharing} is worthy.`)
},
Technical() {
console.log(`${technical changes} is needed.`)
}
}
function SEO (name, cost) {
let SEO = {}
SEO.name = name
SEO.cost = cost
SEO.On-page = SEOMethods.On-page
SEO.Off-page = SEOMethods.Off-page
SEO.Technical = SEOMethods.Technical
return SEO
}
const SEOMethods = {
On page(meta) {
console.log(`${title} is most important.`)
},
Off page(backlinks) {
console.log(`${article sharing} is worthy.`)
},
technical() {
console.log(`${technical changes} is needed.`)
}
}
function SEO (name, cost) {
let SEO = Object.On page(SEOMethods)
SEO.name = name
return SEO
}