@@ -457,6 +457,61 @@ static VALUE _rb_js_proc_to_js(VALUE obj) {
457
457
return jsvalue_s_new (rb_js_abi_host_proc_to_js_function ((uint32_t )obj ));
458
458
}
459
459
460
+ /*
461
+ * Document-module: JS
462
+ *
463
+ * The JS module provides a way to interact with JavaScript from Ruby.
464
+ *
465
+ * == Example
466
+ *
467
+ * A simple eval and object access:
468
+ *
469
+ * require 'js'
470
+ * JS.eval("return 1 + 2") # => 3
471
+ * JS.global[:document].write("Hello, world!")
472
+ * JS.global[:document].addEventListner("click") do |event|
473
+ * puts event # => # [object MouseEvent]
474
+ * puts event[:detail] # => 1
475
+ * end
476
+ *
477
+ */
478
+
479
+ /*
480
+ * Document-class: JS::Object
481
+ *
482
+ * A JS::Object represents a JavaScript object.
483
+ * Note that JS::Object can represent a JavaScript object that represents a Ruby
484
+ * object (RbValue).
485
+ *
486
+ * == Example
487
+ *
488
+ * A simple object access:
489
+ *
490
+ * require 'js'
491
+ * document = JS.global[:document] # => # [object HTMLDocument]
492
+ * document[:title] # => "Hello, world!"
493
+ * document[:title] = "Hello, Ruby!"
494
+ *
495
+ * document.write("Hello, world!") # is equivalent to the following:
496
+ * document.call(:write, "Hello, world!")
497
+ * js_obj = JS.eval(<<-JS)
498
+ * return {
499
+ * method1: function(str, num) {
500
+ * // str is a JavaScript string and num is a JavaScript number.
501
+ * str.length + num
502
+ * },
503
+ * method2: function(rbObject) {
504
+ * // Call String#upcase method for the given Ruby object (RbValue).
505
+ * return rbObject.call("upcase").toString();
506
+ * }
507
+ * }
508
+ * JS
509
+ * # Non JS::Object args are automatically converted to JS::Object by `to_js`.
510
+ * js_obj[:method1].call("Hello", 5) # => 10
511
+ * js_obj[:method2].call(JS.wrap("Hello, Ruby"))
512
+ * # => "HELLO, RUBY" (JS::Object)
513
+ */
514
+
460
515
/*
461
516
* JavaScript interoperations module
462
517
*/
0 commit comments