7 kyu

JavaScript class-like objects

11,095 of 11,337jhoffner
Description
Loading description...
Object-oriented Programming
Fundamentals
  • Please sign in or sign up to leave a comment.
  • trashy_incel Avatar

    this kata is outdated since JavaScript has had proper classes. it should either be retired or change every instance of "class-like" to "class"

  • rsschool_28bac8bd66bcb83b Avatar

    Error "Response received but no data was written to STDOUT or STDERR."

  • BrwnChiknBrwnCow Avatar

    No sample tests? It is unclear what I am supposed to do here. I'm not keen on your sample test procedures. Going back to leetcode.

  • isvishalrana Avatar

    no sample tests, not able to understand the error

  • harsh_rk_singh Avatar

    Please add test cases for this

  • Paul Asaf Avatar

    The tests don't tell us anything about where the error is.

  • trashy_incel Avatar

    no sample tests

  • marcosantoniodev Avatar

    why the description says "class-like object" and not just "class"? There's some difference? It's a real doubt.

  • marcosantoniodev Avatar

    templates literals doesn't work, WHY?

    Is it because version of Node?

  • rsschool_a5db49daabf52ac9 Avatar

    Сломал голову пока думал почему тесты не проходят, но случайно нажал Submit и все прошло. Первый раз такое вижу, теплых слов автору...

  • sarahcodez Avatar

    This comment has been hidden.

  • wxl Avatar

    This comment has been hidden.

  • lastunicorn Avatar

    i receive this error, too: "animal.toString() does not return correct value"

    i made tests and it returns exactly what the kata's description say. the test does not provide any description about the error. is it the test wrong?

  • apearsonae Avatar

    Seems broken, finally hit the cheat button and pasted successful code and still getting 'Unknown Error'.

  • user4225506 Avatar

    I'm stumped by why I received this error on the last test, when I submitted my solution: Test Failed: animal.toString() does not return correct value. I even took my code and ran it in JSFiddle & it ran without any errors.

  • norange Avatar

    I'm a puzzled by the "Test Failed: animal.toString() does not return correct value" error even though I have defined the toString method which returns a sentence containing this.type and this.name.

    What is actually expected from this method ?

    Thanks

  • shellfishmeme Avatar

    The explanation doesn't mention that the object properties have to be mutable. I used object.create and had the last test fail because I didn't set the attributes to be writable.

    It should explicitly mention that your object should support 'foo.name = "bar";'

  • romerramos Avatar

    If type starts with a vowel then... "Max is a alligator" is correct?

  • DKunin Avatar

    Nice kata - always train the basics)

  • hc000 Avatar

    my code for the tostring is correct however it keeps failing the test?? tried multiple different way of setting it, using proto and prototype both inside and outside of the original class...

  • sactor Avatar

    This comment has been hidden.

  • bebop Avatar

    does anyone know why i get "Failed to construct test fixture properly" after hitting the "Test" button, but on submit it says i am good to go?

  • BigAB Avatar

    Also I believe you would take far more of a "performance hit" from defining and allocating a new function on every instance constructed than the minuscule "performance hit" of looking up the prototype chain. Not that either of these would be significant in the example but because we are talking about fundamentals for new js coders I'd say the former (allocating new functions) would be "far worse" than the prototype look up.

  • bkimmel Avatar

    The two sort of cardinal approaches I see here are, 1: putting the toString method in the constructor itself and 2. Attaching it via the constructor's prototype. I considered both, but did 1 because I know you take a small performance hit when your object has to go climbing up it proto chain to find things... are there any concrete drawbacks to using 1 over 2? One I can think of is that iterating over the object with hasOwnProperty will include the toString, where it might be a bit cleaner to just have name and type... thoughts?