dart-lang/js-interop — pull request #52 by a14n (2013-03-12 17:52:51+00:00)
Title: Provide a way to wrap js

This PR allows to wrap js lib as a dart lib.

For example, starting with the following js code :

```js
function Person(firstname, lastname){
this.firstname = firstname;
this.lastname = lastname;
this.children = [];
};
Person.prototype.sayHello = function() {
return "Hello, I'm " + this.firstname + " " + this.lastname;
};
```

You can wrap it in a dart Object :

```dart
class Person extends jsw.TypedProxy {
Person(String firstname, String lastname) :
super(js.context.Person, [firstname, lastname]);
Person.fromProxy(js.Proxy proxy) : super.fromProxy(proxy);

set firstname(String firstname) => $unsafe.firstname = firstname;
String get firstname => $unsafe.firstname;

set lastname(String lastname) => $unsafe.lastname = lastname;
String get lastname => $unsafe.lastname;

List get children => new jsw.JsArrayToListAdapter.fromProxy(
$unsafe.children, new jsw.TranslatorForProxy((p) => new Person.fromProxy(p)));

String sayHello() => $unsafe.sayHello();
}
```

Once done, you can use dart `Person` in a strong typed way like that :

```dart
main(){
js.scoped((){
final julia = new Person('Julia', 'Doe');
final jack = new Person('Jack', 'Doe');
final john = new Person('John', 'Doe');
john.children.addAll([julia, jack]);
printChildrenNames(john);
});
}
void printChildrenNames(Person p) {
print(p.children.map((c) => c.firstname).join(', '));
}
```