Prototyping in JavaScript

Prototyping in JavaScript

The prototype property is an object (called as prototype object) has a constructor property by default. constructor property points back to the function on which the prototype object is a property. We can access the function’s prototype property using the syntax functionName.prototype.
I usually loved to work on Python has many inbuilt methods like the title.
While working on the front-end part I prefer to use JQuery or Plain Vanilla javascript. I found some lack of method like the title. So I decided to build a method which does the same action as the title in python.
First, I build a simple method which takes a string as an argument which makes the title for that string.
After 5-6 months working in front-end technology, I came to know about Prototyping in Javascript.

Prototype for the title the string.
String.prototype.title = function() {
    if (this == "None" || this == "") {
        return "-"
    }
    var string = this.toLowerCase()
    string = string.replace(/(^|\s)[a-z]/g,function(f){return f.toUpperCase();});
    return string.replace(/_/g, " ").replace(/-/g, " ")
}
Prototype for the INR Symbol.
Number.prototype.getINR = function() {
    return this.toLocaleString('en-IN',{
        maximumFractionDigits: 2,
        style: 'currency',
        currency: 'INR'})
}
usage: let amount = 50
           amount.getINR()
       console.log(amount)
       > '₹ 50.0'

Comments

  1. This is really a good source of information, I will often follow it to know more information and expand my knowledge, I think everyone should know it, thanks Best Rapid prototyping service provider

    ReplyDelete
  2. No deposit bonus casinos 2021 | How to get free spins no deposit
    Most 먹튀검증소 casinos 19 동인지 will limit you to 5 no deposit spins with no deposit 가상축구 required to activate any bonus without 토팡 any deposit required. However, in addition to free spins, 토토사이트 관리 알바 벳피스트

    ReplyDelete
  3. Casinos in the UK - How to find good games - GrizzGo
    So, what do we mean by “casinos in the UK”? to find a casino and live หารายได้เสริม casino poormansguidetocasinogambling.com games worrione on a septcasino.com mobile gri-go.com phone device in 2021.

    ReplyDelete

Post a Comment

Popular Posts