2 ms·
I plan on having classes, and I plan for classes to support both functions and procedures as members. If you think about it, classes already have "pure function
by brundolf 5y ago
I plan on having classes, and I plan for classes to support both functions and procedures as members. If you think about it, classes already have "pure functions of themselves" in the form of getters! JS/TS has just never been able to enforce that purity before, which meant that you could technically access a property and have a side-effect:
class Foo {
get prop1() {
this.state = Math.random();
return this.state;
}
}
console.log(myFoo.prop1)
console.log(myFoo.prop1) // different!
So I think the func/proc distinction will line up really nicely with classes as containers of state. And, as in other cases, pure functions will be able to access properties and call pure functions on class instances, just not call their procedures
Other things I'm going to try out with classes are getting rid of inheritance, and adding a publicly-readable-but-privately-writable access modifier for properties