At any stage I can change an object box.name = "Bob" Īnd in the strict class definition it is no longer a true instanceOf Box, it has been mutated. Without the strict classing of languages like C++ and Java there is no real object type. Though closer to real polymorphism it still is not class safe. Or you can use the class syntax or direct to prototype and have a stricter form of inheritance via prototypes. You can make the object factory smart and add properties and functions depending on the parts its made of. Personally I don't like to use the term polymorphic in JS as JS does not really define an interface, however as shown below you could consider polymorphic like behaviours function position(x,y)) In a sense the ultimate form of polymorphism, truly independent of type and thoroughly unsafe as is any super power if you don't learn to use it with care. ![]() The requirement be only that they provide the correct set of properties and behaviours for shared functions to operate on. It is not the object type that determines the behaviour provided by shared functions (more apt than calling them polymorphic) There are a wide variety of ways to define objects and functions for the objects. (*) (not a real term in CS as far as I know) ![]() That also does not constitute an example of polymorphism. ![]() I overlooked the assignment of a new function to the object named triangle. Just giving them different names does not change the type. No that is not an example of polymorphism as each instance is the same object.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |