2 ms·
There was also a different proposal that allows objects to be extended: https://github.com/tc39/proposal-bind-operator https://github.com/tc39/proposal-bind-ope
by renke1 4y ago
There was also a different proposal that allows objects to be extended: https://github.com/tc39/proposal-bind-operator https://github.com/tc39/proposal-bind-operator
Personally, I don't use classes much, but sometimes I think free functions are a little too hard to find, so I tend to experiment with the following pattern.
interface User { … }
const User = {
rename(user: User, newName: string): User { … },
getDisplayName(user: User): string { … }
}
const renke: User = { … }
console.log(User.getDisplayName(renke));
Which makes finding an operation for a certain type easier to find (just write User and trigger autocomplete).
The alternative is of course having renameUser (or userRename) and getUserDisplayName (or userGetDisplayname). The prefixed version would make autocomplete easier also.
- galaxyLogic 4y agoJava has https://www.eclipse.org/xtend/ https://www.eclipse.org/xtend/
- pharmakom 4y agoThis is the beauty of pipeline operator. It adds very little extra machinery - it’s just an infix operator that makes working with free functions easier.