choonkeat choonkeat 4 months ago

2ality - technology, life
The closest thing you can achieve in JavaScript is fake operator overloading – triggering two method calls: obj1.valueOf() obj2.valueOf() Those are made because + only works with primitive values and thus needs to convert obj1 and obj2 to primitives. It does so by invoking their valueOf() method. Fake operator overloading is much less useful than real operator overloading: You don’t get access to both operands at the same time and you can’t influence the value returned by + . We’ll later look at tricks that work around these limitations.
- Annotation on Fake operator overloading in JavaScript

Share this annotation

Post to Basecamp Project Update Twitter Bookmark on Del.icio.us Send E-mail Post to a Blog Post to Backpack Post to Trac Post to Bugzilla Post to a Tumblr Update Friendfeed Posterous

paste in your blog
 
paste anywhere: IM, mail
 
give this link to a friend
 

Tags: dec_11, 2ality.com, annotations
Comments are allowed
This copy is published

Note: "This copy is kept-secret" would mean its URL is not published, but anyone knowing its URL can still view it.