Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //object architecture
- //DefineProperty
- // -configurable
- // -writable
- // - eneumerable
- // - get
- // - set
- //prototype chain
- 'use strict'
- // const samim = {
- // firstName: 'samim',
- // lastName: 'Hasan',
- // get age() {
- // return this._age + 'Years old'
- // },
- // set age(age) {
- // if (age < 18) {
- // throw new Error('Minors are not allowed')
- // }
- // this._age = age
- // },
- // fullName() {
- // return this.firstName + ' ' + this.lastName
- // }
- // }
- // Object.defineProperty(samim, '_age', {
- // value: '28',
- // writable: true,
- // enumerable: true,
- // configurable: false
- // })
- //proxy
- //constructor
- //OOJ principle
- //encapsulation
- //Abstraction
- //Inheritance
- //polymorphism
- //creational design pattern (constructor pattern)
- function Profile(firstName, lastName) {
- let _age = 28
- this.firstName = firstName
- this.lastName = lastName
- // this.age = age
- Object.defineProperty(this, 'age', {
- get() {
- return _age + 'Years old'
- },
- set(age) {
- if (age < 17) {
- throw new Error('Minors are not allowed')
- }
- _age = age
- }
- })
- }
- Profile.prototype.fullName = function () {
- return this.firstName + ' ' + this.lastName
- }
- function ProfessionalProfile(firstName, lastName, profession) {
- Profile.call(this, firstName, lastName)
- this.profession = profession
- }
- ProfessionalProfile.prototype = Object.create(Profile.prototype)
- ProfessionalProfile.prototype.professionalName = function () {
- return this.firstName + ' ' + this.lastName + '-' + this.profession
- }
- //setting up lost constructor
- ProfessionalProfile.prototype.constructor = ProfessionalProfile
- const samim = new Profile('samim', 'Hasan')
- const samimP = new ProfessionalProfile('samim', 'Hasan', 'web programmer')
- //constructor to class
- class Profile {
- #_age = 28
- constructor(firstName, lastName) {
- this.firstName = firstName
- this.lastName = lastName
- }
- get age() {
- return this.#_age + 'years old'
- }
- set age(age) {
- if (age < 18) {
- throw new Error('Minors are not allowed')
- }
- this.#_age = age
- }
- fullName() {
- return this.firstName + ' ' + this.lastName
- }
- }
- class ProfessionalProfile extends Profile {
- constructor(firstName, lastName, profession) {
- super(firstName, lastName)
- this.profession = profession
- }
- fullName() {
- return 'Senior Programmer- ' + super.fullName()
- }
- professionalName() {
- return super.fullName() + '-' + this.profession
- }
- }
- const samim = new Profile('samim', 'Hasan')
- const samimP = new ProfessionalProfile('samim', 'Hasan', 'web programmer')
- const khalil = new Profile('khalil', 'Rahman')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement