Pop quiz: suppose you see two Closure Compiler type annotations.
A) {function(Object)}
B) {function(Array)}
Which one is the subtype?
Telling you that the right answer is (A) feels a lot like driving on the wrong side of the road. Try reading it out loud.
Right Answer: "A function taking an Object IS A function taking an Array"
Wrong Answer: "A function taking an Array IS A function taking an Object"
Saying the right answer feels so wrong! Saying the wrong answer feels so right! We often have to do multiple rounds of whiteboarding the problem to try to explain it to other JS engineers.
This is not a unique problem to JavaScript. Most object oriented languages have the same issue. But JavaScript engineers are used to living without types. With Closure, suddenly you have types. And you have lots of complex function types that real OO languages don't have, and that you're probably unfamiliar with if you haven't used a functional language.
The problem, I think, goes back to a lot of "Intro to Objects and Classes" books that teach the "is-a" relationship. An apple IS A fruit. A blog IS A website. A werewolf IS A man but also IS A wolf.
The "is-a" wording is an oversimplification that breaks down if you're not careful. This wikipedia page gives a good counterexample, obtusely explained. Suppose you define "A Doctor" as a person that can treat all patients, and a Pediatrician as a person that can only treat children. If we need a Doctor that can treat all patients, then a Pediatrician is not an acceptable substitude. So, counterintuitively, a Pediatrician is not a subclass a Doctor.
Oddly, a Pediatrician is a superclass of this "Doctor." If you need a pediatrician, a doctor that can treat all patients is an acceptable substitute.
What you really want is to define a Doctor as "a person that can treat at least one patient." You might call this the Empty Doctor or (for the calculus nerds) the Epsilon Doctor. This doctor can treat some patient, somewhere. But if you go to see the Epsilon Doctor, it's likely that they won't know how to treat you. A pediatrician is a subclass of the Epsilon Doctor, because a pediatrician can treat some patients.
Conversely, when you have a {function(Object)}
, this does not mean "a function that can take some object". It means "a function that knows how to handle all objects." A {function(Object)}
is substitutable any place you need a {function(Array)}
.
download Subtyping Functions Without Poking Your Eyes Out subtitle indonesia samehadaku, nonton Subtyping Functions Without Poking Your Eyes Out Sub indo awsubs, Subtyping Functions Without Poking Your Eyes Out Bahasa indonesia animeindo, Subtyping Functions Without Poking Your Eyes Out Sub indonesia naruchigo mangaku, Subtyping Functions Without Poking Your Eyes Out mangachan, Subtyping Functions Without Poking Your Eyes Out mp3, Subtyping Functions Without Poking Your Eyes Out mp4, Subtyping Functions Without Poking Your Eyes Out 720p,Subtyping Functions Without Poking Your Eyes Out hd sub indo, Subtyping Functions Without Poking Your Eyes Out ost
Subtyping Functions Without Poking Your Eyes Out
,Subtyping Functions Without Poking Your Eyes Out sub indo
nonton Subtyping Functions Without Poking Your Eyes Out sub indo awsubs, sub indo Subtyping Functions Without Poking Your Eyes Out episode, episode Subtyping Functions Without Poking Your Eyes Out indonesia oploverz, Download Anime Subtyping Functions Without Poking Your Eyes Out Google Drive, download anime BD Subtyping Functions Without Poking Your Eyes Out 3gp,Subtyping Functions Without Poking Your Eyes Out mp4,Subtyping Functions Without Poking Your Eyes Out mkv, Subtyping Functions Without Poking Your Eyes Out google drive, Subtyping Functions Without Poking Your Eyes Out 480p,Subtyping Functions Without Poking Your Eyes Out 720p, sub indo Subtyping Functions Without Poking Your Eyes Out,download naruto sub indo, naruto shippuden sub indo, download naruto shipuden sub indo, nonton naruto sub indo, naruto subtitle indonesia, naruto episode indonesia, naruto episode 465 sub indo, download naruto episode, download one piece sub indo, one piece sub indo, download one piece sub indo, nonton one piece sub indo, one piece subtitle indonesia, one piece episode indonesia, Subtyping Functions Without Poking Your Eyes Out batch animeindo, download one piece episode, one piece animeindo, naruto animeindo, naruto awsubs, one piece awsubs
EmoticonEmoticon