This is not a great technical question, but a little one that arised out of my curiosity.
It doesn't particularly concern JS but I guess you guys will tolerate that😅
(The follow isn't valid JS syntax! sorry!!)
It looks like this:
exposed function Greet(name) {
let fullName;
for(let i = 0; i <= 500; i++)
console.log(i)
// some other statements
function sayHi() {
alert( "Hi " + name )
}
function sayHello() {
alert( "Hello " + name )
}
function sayGoodBye() {
alert( "Good bye " + name )
}
let #nickname = "Adios"
function #makeFullName() {
fullName = #nickname + " " + name
}
}
Or a function like:
function Greet(name) {
let fullName;
for(let i = 0; i <= 500; i++)
console.log(i)
// some other statements
function sayHi() {
alert( "Hi " + name )
}
function sayHello() {
alert( "Hello " + name )
}
function sayGoodBye() {
alert( "Good bye " + name )
}
let nickname = "Adios"
function makeFullName() {
fullName = nickname + " " + name
}
return export { fullName, sayHi, sayHello, sayGoodBye }
}
greet1 = new Greet("Myself")
greet1.sayHi()
greet2 = new Greet("Myself")
greet2.sayHello()
greet3 = new Greet("Myself")
greet3.sayGoodBye()
greet3.#nickname // Error
Why isn't this sort of functions used in programming languages?
I very well know that JS can do:
function Circle(x, y, r) {
this.x = x
this.y = y
this.r = r
this.draw = () => //Draw it
}
let c = new Circle(100, 100, 10)
Thanks for any help👍