equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
43 |
43 |
44 __new__: function(arg1, arg2) { |
44 __new__: function(arg1, arg2) { |
45 print("new with " + arg1 + ", " + arg2); |
45 print("new with " + arg1 + ", " + arg2); |
46 }, |
46 }, |
47 |
47 |
48 __getIds__: function() { |
48 __getKeys__: function() { |
49 print("__getIds__ called"); |
49 print("__getKeys__ called"); |
50 return [ "foo", "bar" ]; |
50 return [ "foo", "bar" ]; |
51 }, |
51 }, |
52 |
52 |
53 __getValues__: function() { |
53 __getValues__: function() { |
54 print("__getValues__ called"); |
54 print("__getValues__ called"); |
76 obj.func("hello", "world"); |
76 obj.func("hello", "world"); |
77 |
77 |
78 // calls __new__ |
78 // calls __new__ |
79 new obj("hey!", "it works!"); |
79 new obj("hey!", "it works!"); |
80 |
80 |
|
81 // calls __getKeys__ |
81 for (i in obj) { |
82 for (i in obj) { |
82 print(i); |
83 print(i); |
83 } |
84 } |
84 |
85 |
|
86 // calls __getValues__ |
85 for each (i in obj) { |
87 for each (i in obj) { |
86 print(i); |
88 print(i); |
87 } |
89 } |
88 |
90 |
|
91 // calls __has__ |
89 var x = "foo" in obj; |
92 var x = "foo" in obj; |
90 print(x); |
93 print(x); |
91 |
94 |
|
95 // calls __has__ |
92 var y = "js" in obj; |
96 var y = "js" in obj; |
93 print(y); |
97 print(y); |
94 |
98 |
|
99 // calls __delete__ |
95 print(delete obj.prop); |
100 print(delete obj.prop); |
96 |
101 |
|
102 // call __get__ and __set__ |
97 print(obj["js"]); |
103 print(obj["js"]); |
98 obj["js"] = "javascript"; |
104 obj["js"] = "javascript"; |
99 print(obj["javascript"]); |
105 print(obj["javascript"]); |