Skip to content

Instantly share code, notes, and snippets.

@SidWorks
Last active February 5, 2022 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SidWorks/8d08cc128689e5ea36508791c183c211 to your computer and use it in GitHub Desktop.
Save SidWorks/8d08cc128689e5ea36508791c183c211 to your computer and use it in GitHub Desktop.
Classless JavaScript- Use Modules Instead of Classes
class Sentence{
constructor(phrase){
this.phrase = phrase
}
startCase(){
this.phrase = this.phrase
.toLowerCase()
.split(' ')
.map(s => s.charAt(0).toUpperCase() + s.substring(1))
.join(' ')
}
putQuotation(){
this.phrase = `"${this.phrase}"`
}
get quote(){
return this.phrase
}
}
const phrase = new Sentence("There is no secret ingredient, it’s just you")
phrase.startCase()
phrase.putQuotation()
const newName = phrase.quote
console.log(newName)
// "There Is No Secret Ingredient, It’s Just You"
class Sentence {
static startCase(phrase) {
return phrase
.toLowerCase()
.split(' ')
.map((s) => s.charAt(0).toUpperCase() + s.substring(1))
.join(' ')
}
static putQuotation(phrase) {
return `"${phrase}"`
}
}
const startCase = Sentence.startCase("There is no secret ingredient, it’s just you")
const quote = Sentence.putQuotation(startCase)
console.log(quote)
// "There Is No Secret Ingredient, It’s Just You"
export function startCase(phrase){
return phrase
.toLowerCase()
.split(' ')
.map((s) => s.charAt(0).toUpperCase() + s.substring(1))
.join(' ')
}
export function getQuotation(phrase){
return `"${phrase}"`
}
import {startCase, getQuotation as Sentence} from './sentence'
const phrase = Sentence.startCase('somnath singh')
const quote = Sentence.getQuotaion(phrase)
console.log(quote)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment