You can get at the prototype [of an object] by using Object.getPrototypeOf. We added this specifically for Caja, because in doing DOM-taming they sometimes needed to be able to chase down the content of objects in order to figure out what they were. We’re hoping that people do not use this method. You don’t need to do it. Generally, if you’re programming correctly, you don’t care about the heritage of the language. You don’t want to ask ‘what are you an instance of?’ because you don’t care, you just want to know: ‘do you have the function that I need in order to get this done? If yes, I’m going to call you. If not, I’m going to throw an exception, because that’s the right thing to do.’ But you shouldn’t care about where an object came from, you shouldn’t care about what it inherits from, you just care about what it can do.From this I have learned the following:
1.
Object.getPrototypeOf was added to JavaScript for Caja only. The architects of JavaScript recommend that you don't use it.2. I'm not familiar with Caja but it sounds like it may have been programmed incorrectly.
3. All this time I have been defining classes in ActionScript has been wasted. I should have just saved time and used dynamic objects everywhere.
4. The solution to everyone's problems is to simply program correctly. Why didn't I think of this before?
How to program correctly:
It doesn't matter where an object came from or what it is. Just start using it blindly and see what happens. Manipulate the properties of that object any way you want and then pass in your parameters to a function you expect to work. If it turns out the object didn't have the function you wanted, no worries because it'll throw an exception. When anyone wants to use your code, just tell them to program correctly too and everything will work out.
No comments:
Post a Comment