001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package js.core;
021 
022 import js.*;
023 
024 /**
025  * <p>An <b>opaque</b> class representing JavaScript function.</p>
026  *
027  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
028  * @see JsGlobal.Function#create()
029  * @see JsGlobal.Function#create(String)
030  * @see JsGlobal.Function#create(String, String)
031  * @see JsGlobal.Function#create(Vars, String)
032  * @see js.Function
033  * @see js.Js#function()
034  * @see js.Js#function(String)
035  * @see js.Js#function(String, String)
036  * @see js.Js#function(Vars, String)
037  * 
038  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be 
039  * generated into the target codes. Re-compilers must exit with error on the operations of 
040  * accessing that kind of class objects.
041  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored 
042  * and <tt>instanceof</tt> to it always <tt>true</tt>.
043  */
044 public class JsFunction<T> extends JsClass
045 {
046     /**
047      * <p>An <b>internal</b> class containing membership data for its enclosing 
048      * opaque class.</p>
049      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or 
050      * class members.</p>
051      *
052      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
053      * 
054      * @javascript Re-compilers must report error on resolving an <b>internal</b> class. 
055      */
056     protected static abstract class Members extends JsClass.Members
057     {
058         /**
059          * <p>An <b>internal</b> static field defining a member ID of the field name and 
060          * used internally to define a member of the same name.</p>
061          * @since 1.0
062          * @see JsFunction#length
063          * @see Member#length
064          * @javascript Re-compilers must report error on accessing an <b>internal</b> field. 
065          */
066         public final static Mid length    = id("length"   );
067     }
068 
069     /**
070      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
071      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
072      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
073      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
074      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
075      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
076      * either circumstance, the field names must be exactly same as the member names, as 
077      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
078      * based on the field names.</p>
079      *
080      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
081      * 
082      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created 
083      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
084      * of class objects.
085      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in 
086      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
087      * <pre>q.m</pre>
088      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier 
089      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
090      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
091      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
092      * <pre>m</pre>
093      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report 
094      * error on the access to <b>opaque</b> fields declared by this class under any other 
095      * circumstances.
096      */
097     public static class Member<T> extends JsClass.Member
098     {
099         private final Generic<?> rWrapper;
100 
101         /**
102          * <p>Internally constructs a member based on a qualifying member with a generic 
103          * wrapper.</p>
104          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
105          * or <b>internal</b> classes or class members.</p>
106          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
107          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
108          * declared in the declaring class of this constructor itself or its subclasses. 
109          * Under this circumstance, the field names must be exactly same as the member 
110          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
111          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly 
112          * to their names appending to the name resolved from the specified qualifying 
113          * member with a dot in between.</p>
114          * @param q A qualifying member
115          * @param mid The ID of the member to construct
116          * @param rWrapper The generic wrapper
117          * @since 1.0
118          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
119          */
120         public Member(JsObject.Member q, Mid mid, Generic<?> rWrapper) {
121             super(q, mid);
122             this.rWrapper = rWrapper;
123         }
124         /**
125          * <p>Internally constructs a member without a qualifying member but a generic 
126          * wrapper.</p>
127          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
128          * or <b>internal</b> classes or class members.</p>
129          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
130          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
131          * declared in <b>opaque</b> types other than the declaring class of this constructor 
132          * itself and its subclasses. Under this circumstance, the field names must be 
133          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b> 
134          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
135          * @param mid The ID of the member to construct
136          * @param rWrapper The generic wrapper
137          * @since 1.0
138          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
139          */
140         public Member(Mid mid, Generic<?> rWrapper) {
141             super(mid);
142             this.rWrapper = rWrapper;
143         }
144         /**
145          * <p>Internally constructs a member based on a qualifying member.</p>
146          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
147          * or <b>internal</b> classes or class members.</p>
148          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
149          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
150          * declared in the declaring class of this constructor itself or its subclasses. 
151          * Under this circumstance, the field names must be exactly same as the member 
152          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
153          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly 
154          * to their names appending to the name resolved from the specified qualifying 
155          * member with a dot in between.</p>
156          * @param q A qualifying member
157          * @param mid The ID of the member to construct
158          * @since 1.0
159          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
160          */
161         public Member(JsObject.Member q, Mid mid) {
162             this(q, mid, null);
163         }
164         /**
165          * <p>Internally constructs a member without a qualifying member.</p>
166          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
167          * or <b>internal</b> classes or class members.</p>
168          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
169          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
170          * declared in <b>opaque</b> types other than the declaring class of this constructor 
171          * itself and its subclasses. Under this circumstance, the field names must be 
172          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b> 
173          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
174          * @param mid The ID of the member to construct
175          * @since 1.0
176          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
177          */
178         public Member(Mid mid) {
179             this(mid, null);
180         }
181 
182         /**
183          * <p>Evaluates the property, represented by the current member instance, of the 
184          * argument object.</p>
185          * @param o The argument object
186          * @return The value of the current member based on the object argument.
187          * @since 1.0
188          * @javascript Re-compilers must convert the instance invocation of this method into 
189          * the JavaScript expression: 
190          * <pre>o.m</pre>
191          * where <tt>m</tt> is the identifier name resolved from the current member 
192          * instance of the invocation.
193          */
194         @Override
195         public JsFunction<T> with(ObjectLike o) {
196             return new JsFunction<T>((JsObject)var(o).var(mid()), rWrapper);
197         }
198         /**
199          * <p>Evaluates a property, represented by the current member instance, of the 
200          * JavaScript global object, that is, evaluates the member to a global identifier.</p>
201          * @return The value of the current member based on the JavaScript global object.
202          * @since 1.0
203          * @javascript Re-compilers must convert the instance invocation of this method into 
204          * the JavaScript expression: 
205          * <pre>m</pre>
206          * where <tt>m</tt> is the identifier name resolved from the current member 
207          * instance of the invocation.
208          */
209         public JsFunction<T> with() {
210             return with(Js.core());
211         }
212 
213         /**
214          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the 
215          * name of this field, qualified by the current member instance of the field, and 
216          * to access the property of the name on an object.</p>
217          * <p>The <tt>length</tt> property of a function specifies the number of named 
218          * arguments declared when the function was defined. The function may actually 
219          * be invoked with more than or fewer than this number of arguments. Don't 
220          * confuse this property of a Function object with the <tt>length</tt> property 
221          * of the Arguments object (see {@link js.Function.Arguments#length()}), which 
222          * specifies the number of arguments actually passed to the function.</p>
223          * @since 1.0
224          * @javascript Re-compilers must resolve the member of this instance field to the 
225          * identifier of the field name appending to the identifier resolved from its 
226          * qualifying member with a dot in between.
227          */
228         public final Value.Integer.Member length = new Value.Integer.Member(this, Members.length);
229     }
230 
231     /**
232      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
233      * without a qualifying member and to access the property of the name on an object.</p>
234      * <p>The <tt>constructor</tt> property of an object is a reference to the function 
235      * that was the constructor for that object.</p>
236      * <p>A common use of the <tt>constructor</tt> property is to determine the type of unknown 
237      * objects. Given an unknown value, you can use the {@link js.Js#typeof(Object)} operation 
238      * to determine whether it is a primitive value or an object. If it is an object, you can 
239      * use the <tt>constructor</tt> property to determine what type of object it is.</p>
240      * <p>Note, however, that while this technique works for the objects built into core 
241      * JavaScript, it is not guaranteed to work with host objects such as the <tt>window</tt> 
242      * object of client-side JavaScript. The default implementation of the <tt>toString()</tt> 
243      * method provides another way to determine the type of an unknown object.</p>
244      * @since 1.0
245      * @javascript Re-compilers must resolve the member of this static field to the 
246      * identifier of the field name.
247      */
248     public static final JsFunction.Member<JsFunction<?>> constructor = new JsFunction.Member<JsFunction<?>>(Members.constructor, Generic.get(JsFunction.class));
249     /**
250      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
251      * without a qualifying member and to access the property of the name on an object.</p>
252      * @since 1.0
253      * @see JsFunction#valueOf()
254      * @javascript Re-compilers must resolve the member of this static field to the 
255      * identifier of the field name.
256      */
257     public static final JsFunction.Member<JsFunction<?>> valueOf = new JsFunction.Member<JsFunction<?>>(Members.valueOf, Generic.get(JsFunction.class));
258     /**
259      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
260      * without a qualifying member and to access the property of the name on an object.</p>
261      * <p>The <tt>length</tt> property of a function specifies the number of named 
262      * arguments declared when the function was defined. The function may actually 
263      * be invoked with more than or fewer than this number of arguments. Don't 
264      * confuse this property of a Function object with the <tt>length</tt> property 
265      * of the Arguments object (see {@link js.Function.Arguments#length()}), which 
266      * specifies the number of arguments actually passed to the function.</p>
267      * @since 1.0
268      * @javascript Re-compilers must resolve the member of this static field to the 
269      * identifier of the field name.
270      */
271     public static final Value.Integer.Member length = new Value.Integer.Member(Members.length);
272 
273     /**
274      * <p>Internally constructs a function object.</p>
275      * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> or 
276      * <b>internal</b> classes or class members.</p>
277      * @since 1.0
278      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
279      */
280     protected JsFunction(Object var) {
281         super((JsObject)var);
282     }
283     /**
284      * <p>Internally casts an <b>opaque</b> object to the current <b>opaque</b> type by 
285      * wrapping it with the wrapping constructor that uses a generic wrapper.</p>
286      * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> or 
287      * <b>internal</b> classes or class members.</p>
288      * @param var The argument of an <b>opaque</b> object.
289      * @param rWrapper The generic wrapper.
290      * @since 1.0
291      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
292      */
293     public JsFunction(JsObject var, Generic<?> rWrapper) {
294         super(var(var, rWrapper));
295     }
296     /**
297      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it 
298      * with the wrapping constructor.</p>
299      * @param var The argument of an <b>opaque</b> object.
300      * @since 1.0
301      * @javascript Re-compilers must ignore the construction operation of this constructor, 
302      * that is, replacing it with its only argument.
303      */
304     public JsFunction(JsObject var) {
305         super(var(var, (JsFunction<T>)null));
306     }
307 
308     /**
309      * <p>Simply returns the current boolean instance.</p>
310      * <p>This method is useful for JS Simulation to implement opaque types.</p>
311      * <p>If the current instance is a Java simulated array and the method runs in JS 
312      * Embed Simulation mode, the invocation creates and returns a JavaScript Array object 
313      * as a runtime copy of the current array.</p>
314      * @return The current boolean instance.
315      * @since 1.0
316      * @javascript Re-compilers must ignore the instance invocation of this method, that is, 
317      * replacing it with its current instance.
318      */
319     @SuppressWarnings("unchecked")
320     @Override
321     public JsFunction<T> var() {
322         return (JsFunction<T>)super.var();
323     }
324     /**
325      * <p>Assigns the value of another function instance to the current function object.</p>
326      * @param var The argument function instance.
327      * @return The new instance.
328      * @since 1.0
329      * @javascript Re-compilers must convert the instance invocation of this method into 
330      * the JavaScript expression: 
331      * <pre>o = var</pre>
332      * where <tt>o</tt> is the current instance of the invocation of this method.
333      */
334     @Override
335     public final <S extends JsObject> S var(S var) {
336         var(var, (Generic<S>)null);
337         return var;
338     }
339 
340     /**
341      * <p>Returns the primitive value associated with the current instance, if there is one. 
342      * This invocation simply returns the instance itself for the current instance is an 
343      * object and there is no primitive value for it.</p>
344      * @return The current object itself.
345      * @since 1.0
346      * @javascript Re-compilers must convert the instance invocation of this method directly 
347      * into a JavaScript invocation on its current object instance without changing the 
348      * method name, but expanding variable arguments, if any, into comma-separated values. 
349      */
350     @Override
351     public JsFunction<T> valueOf() {
352         return var().valueOf();
353     }
354 
355     /**
356      * <p>Construct an object with the current function instance.</p>
357      * @return The newly constructed object.
358      * @since 1.0
359      * @javascript Re-compilers must convert this instance invocation into the JavaScript expression: 
360      * <pre>new f()</pre>
361      * where <tt>f</tt> is the current function instance of the invocation of this method.
362      */
363     public JsObject create() {
364         return var().create();
365     }
366     /**
367      * <p>Constructs an object with the current function object, passing the specified 
368      * argument.</p>
369      * @param arg The argument value.
370      * @return The newly constructed object.
371      * @since 1.0
372      * @javascript Re-compilers must convert this instance invocation into the JavaScript expression: 
373      * <pre>new f(arg)</pre>
374      * where <tt>f</tt> is the current function instance of the invocation of this method.
375      */
376     public JsObject create(Object arg) {
377         return var().create(arg);
378     }
379     /**
380      * <p>Construct an object with the current function instance, passing the specified 
381      * arguments.</p>
382      * @param args The list of arguments.
383      * @return The newly constructed object.
384      * @since 1.0
385      * @javascript Re-compilers must convert this instance invocation into the JavaScript expression: 
386      * <pre>new f(args)</pre>
387      * where <tt>f</tt> is the current function instance of the invocation of this method 
388      * and <tt>args</tt> must be expanded into comma-separated arguments.
389      */
390     public JsObject create(Vars<?> args) {
391         return var().create(args);
392     }
393     /**
394      * <p>Invokes the current function instance.</p>
395      * @return The return value of the invocation.
396      * @since 1.0
397      * @javascript Re-compilers must convert the instance invocation of this method into 
398      * the JavaScript expression: 
399      * <pre>f()</pre>
400      * where <tt>f</tt> is the current function instance of the invocation of this method.
401      */
402     public T invoke() {
403         return var().invoke();
404     }
405     /**
406      * <p>Invokes the current function instance, passing the specified argument.</p>
407      * @param arg The argument value.
408      * @return The return value of the invocation.
409      * @since 1.0
410      * @javascript Re-compilers must convert the instance invocation of this method into 
411      * the JavaScript expression: 
412      * <pre>f(arg)</pre>
413      * where <tt>f</tt> is the current function instance of the invocation of this method.
414      */
415     public T invoke(Object arg) {
416         return var().invoke(arg);
417     }
418     /**
419      * <p>Invokes the current function instance, passing the specified arguments.</p>
420      * @param args The list of arguments.
421      * @return The return value of the invocation.
422      * @since 1.0
423      * @javascript Re-compilers must convert the instance invocation of this method into 
424      * the JavaScript expression: 
425      * <pre>f(args)</pre>
426      * where <tt>f</tt> is the current function instance of the invocation of this method 
427      * and <tt>args</tt> must be expanded into comma-separated arguments.
428      */
429     public T invoke(Vars<?> args) {
430         return var().invoke(args);
431     }
432     /**
433      * <p>Invokes the current function instance as a method of a specified scope object.</p>
434      * @param thisobj The scope object.
435      * @return The return value of the invocation.
436      * @throws RuntimeException JavaScript throws a <tt>TypeError</tt> if this method 
437      * is invoked with a scope object that is not a function. See {@link Js#err(Object)} 
438      * and {@link js.core.JsTypeError} for JS Simulation.
439      * @since 1.0
440      * @javascript Re-compilers must convert the instance invocation of this method directly 
441      * into a JavaScript invocation on its current instance without changing the method 
442      * name, but expanding variable arguments, if any, into comma-separated values. 
443      */
444     public T call(Object thisobj) {
445         return var().call(thisobj);
446     }
447     /**
448      * <p>Invokes the current function instance as a method of a specified scope object, 
449      * passing the specified argument.</p>
450      * @param thisobj The scope object.
451      * @param arg The argument value.
452      * @return The return value of the invocation.
453      * @throws RuntimeException JavaScript throws a <tt>TypeError</tt> if this method 
454      * is invoked with a scope object that is not a function. See {@link Js#err(Object)} 
455      * and {@link js.core.JsTypeError} for JS Simulation.
456      * @since 1.0
457      * @javascript Re-compilers must convert the instance invocation of this method directly 
458      * into a JavaScript invocation on its current instance without changing the method 
459      * name, but expanding variable arguments, if any, into comma-separated values. 
460      */
461     public T call(Object thisobj, Object arg) {
462         return var().call(thisobj, arg);
463     }
464     /**
465      * <p>Invokes the current function instance as a method of a specified scope object, 
466      * passing the specified arguments.</p>
467      * @param thisobj The scope object.
468      * @param args The list of arguments.
469      * @return The return value of the invocation.
470      * @throws RuntimeException JavaScript throws a <tt>TypeError</tt> if this method 
471      * is invoked with a scope object that is not a function. See {@link Js#err(Object)} 
472      * and {@link js.core.JsTypeError} for JS Simulation.
473      * @since 1.0
474      * @javascript Re-compilers must convert the instance invocation of this method directly 
475      * into a JavaScript invocation on its current instance without changing the method 
476      * name, but expanding variable arguments, if any, into comma-separated values. 
477      */
478     public T call(Object thisobj, Vars<?> args) {
479         return var().call(thisobj, args);
480     }
481     /**
482      * <p>Invokes the current function instance as a method of a specified scope object.</p>
483      * @param thisobj The scope object.
484      * @return The return value of the invocation.
485      * @throws RuntimeException JavaScript throws a <tt>TypeError</tt> if this method 
486      * is invoked with a scope object that is not a function. See {@link Js#err(Object)} 
487      * and {@link js.core.JsTypeError} for JS Simulation.
488      * @since 1.0
489      * @javascript Re-compilers must convert the instance invocation of this method directly 
490      * into a JavaScript invocation on its current instance without changing the method 
491      * name, but expanding variable arguments, if any, into comma-separated values. 
492      */
493     public T apply(Object thisobj) {
494         return var().apply(thisobj);
495     }
496     /**
497      * <p>Invokes the current function instance as a method of a specified scope object, 
498      * passing the specified array of arguments.</p>
499      * @param thisobj The scope object.
500      * @param args The array of arguments.
501      * @return The return value of the invocation.
502      * @throws RuntimeException JavaScript throws a <tt>TypeError</tt> if this method 
503      * is invoked with a scope object that is not a function or if this method is invoked 
504      * with an argument that is not an array or {@link js.Function.Arguments} object. See 
505      * {@link Js#err(Object)} and {@link js.core.JsTypeError} for JS Simulation.
506      * @since 1.0
507      * @javascript Re-compilers must convert the instance invocation of this method directly 
508      * into a JavaScript invocation on its current instance without changing the method 
509      * name, but expanding variable arguments, if any, into comma-separated values. 
510      */
511     public T apply(Object thisobj, Object args) {
512         return var().apply(thisobj, args);
513     }
514 
515     /**
516      * <p>Logical AND operation, resembling that of JavaScript, performs the Boolean AND 
517      * operation on the two values: it returns <tt>true</tt> if and only if both its first 
518      * operand and its second operand are <tt>true</tt>. If one or both of these operands 
519      * is <tt>false</tt>, it returns <tt>false</tt>.</p>
520      * <p>In JavaScript, depending on the value of the left-side expression, the operator 
521      * may or may not evaluate the right-side expression. The actual behavior of the operator 
522      * is somewhat more complicated. It starts by evaluating its first operand, the expression 
523      * on its left. If the value of this expression can be converted to <tt>false</tt> 
524      * (for example, if the left operand evaluates to <tt>null</tt>, 0, "", or undefined), 
525      * the operator returns the value of the left-side expression. Otherwise, it evaluates 
526      * its second operand, the expression on its right, and returns the value of that 
527      * expression. In JavaScript 1.0 and JavaScript 1.1, if the left-side expression 
528      * evaluates to <tt>false</tt>, the && operator returns <tt>false</tt> rather than 
529      * returning the unconverted value of the left-side expression.</p>
530      * <p>To make the second operand really late-evaluated or not evaluated in JS Simulation 
531      * mode, resembling what happens in JavaScript, you may have to extend {@link Var} 
532      * anonymously, returning the actual expression in the method overriding 
533      * {@link Var#var()}.</p>
534      * <p>Sometimes, this operation probably does not do what the programmers intended. 
535      * To avoid problems, do not use expressions with side effects (assignments, increments, 
536      * decrements, and function calls) for the second operand unless you are quite sure 
537      * you know exactly what you are doing.</p>
538      * <p>Despite the fairly confusing way that this operation actually works, it is 
539      * easiest, and perfectly safe, to think of it as merely a Boolean algebra operator. 
540      * Although it does not actually return a boolean value, the value it returns can always 
541      * be converted to a boolean value.</p>
542      * <p>Note that, this method is probably useful in emulation codes just for perfect 
543      * re-compilations. However, in most cases you can use the logical AND operator of the 
544      * Java language like this:
545      * <pre>Js.be(var) && Js.be(other)</pre>
546      * which is definitely late-evaluated but not necessarily re-compiled into an expected 
547      * JavaScript expression since the Java compilers generally used are free to compile 
548      * the expression into any byte codes they think efficient, making it too hard for the 
549      * re-compilers to reconvert the byte codes to an expression in JavaScript.</p>
550      * @param other A value or object.
551      * @return The logical AND of the two operands.
552      * @since 1.0
553      * @javascript Re-compilers must replace the instance invocation of this method with the 
554      * JavaScript expression:
555      * <pre>p && other</pre>
556      * where <tt>p</tt> is the current function instance of the invocation of this method.
557      */
558     public final JsFunction<T> and(JsFunction<T> other) {
559         return Js.and(this, other);
560     }
561 
562     /**
563      * <p>Logical OR operation, resembling that of JavaScript, performs the Boolean OR 
564      * operation on the two values: it returns <tt>true</tt> if either the first operand or 
565      * the second operand is <tt>true</tt>, or if both are <tt>true</tt>. If both operands 
566      * are <tt>false</tt>, it returns <tt>false</tt>.</p>
567      * <p>In JavaScript, although the || operator is most often used simply as a Boolean OR 
568      * operator, it, like the && operator, has more complex behavior. It starts by evaluating 
569      * its first operand, the expression on its left. If the value of this expression can 
570      * be converted to <tt>true</tt>, it returns the unconverted value of the left-side 
571      * expression. Otherwise, it evaluates its second operand, the expression on its right, 
572      * and returns the value of that expression. In JavaScript 1.0 and JavaScript 1.1, if the 
573      * left-side expression can be converted to <tt>true</tt>, the operator returns <tt>true</tt> 
574      * and doesn't return the unconverted value of the left-side expression.</p>
575      * <p>To make the second operand really late-evaluated or not evaluated in JS Simulation 
576      * mode, resembling what happens in JavaScript, you may have to extend {@link Var} 
577      * anonymously, returning the actual expression in the method overriding 
578      * {@link Var#var()}.</p>
579      * <p>As with the {@link #and(Object)} operation, you should avoid right-side 
580      * operands that include side effects, unless you purposely want to use the fact that 
581      * the right-side expression may not be evaluated in JavaScript.</p>
582      * <p>Even when this operation is used with operands that are not boolean values, it 
583      * can still be considered a Boolean OR operator because its return value, whatever the 
584      * type, can be converted to a boolean value.</p>
585      * <p>Note that, this method is probably useful in emulation codes just for perfect 
586      * re-compilations. However, in most cases you can use the logical OR operator of the 
587      * Java language like this:
588      * <pre>Js.be(var) || Js.be(other)</pre>
589      * which is definitely late-evaluated but not necessarily re-compiled into an expected 
590      * JavaScript expression since the Java compilers generally used are free to compile 
591      * the expression into any byte codes they think efficient, making it too hard for the 
592      * re-compilers to reconvert the byte codes to an expression in JavaScript.</p>
593      * @param other A value or object.
594      * @return The logical OR of the two operands.
595      * @since 1.0
596      * @javascript Re-compilers must replace the instance invocation of this method with the 
597      * JavaScript expression:
598      * <pre>p || other</pre>
599      * where <tt>p</tt> is the current function instance of the invocation of this method.
600      */
601     public final JsFunction<T> or(JsFunction<T> other) {
602         return Js.or(this, other);
603     }
604 
605     /**
606      * <p>Conditional operation, resembling the ternary operator of JavaScript, returns the 
607      * second operand if the first operand evaluates to <tt>true</tt>; Returns the third 
608      * operand, otherwise.</p>
609      * <p>The first operand of the conditional operation must be (or be convertible to) a 
610      * boolean value. Usually this is the result of a comparison operation. The second and 
611      * third operands may have any value. The value returned by the conditional operation 
612      * depends on the boolean value of the first operand. If that operand is <tt>true</tt>, 
613      * the value of the conditional expression is the value of the second operand. If the 
614      * first operand is <tt>false</tt>, the value of the conditional expression is the 
615      * value of the third operand.</p>
616      * <p>To make the second and third operands really late-evaluated or not evaluated in 
617      * JS Simulation mode, resembling what happens in JavaScript, you may have to extend 
618      * {@link Var} anonymously, returning the actual expression in the method overriding 
619      * {@link Var#var()}.</p>
620      * <p>Note that, this method is probably useful in emulation codes just for perfect 
621      * re-compilations. However, in most cases you can use the conditional operator of the 
622      * Java language like this:
623      * <pre>Js.be(test) ? var : other</pre>
624      * which is definitely late-evaluated but not necessarily re-compiled into an expected 
625      * JavaScript expression since the Java compilers generally used are free to compile 
626      * the expression into any byte codes they think efficient, making it too hard for the 
627      * re-compilers to reconvert the byte codes to an expression in JavaScript.</p>
628      * @param other A value or object.
629      * @return The second operand if the first operand evaluates to <tt>true</tt>; Otherwise, 
630      * the third operand.
631      * @since 1.0
632      * @javascript Re-compilers must replace the instance invocation of this method with the 
633      * JavaScript expression:
634      * <pre>test ? p : other</pre>
635      * where <tt>p</tt> is the current function instance of the invocation of this method.
636      */
637     public final JsFunction<T> cond(Object test, JsFunction<T> other) {
638         return Js.cond(test, this, other);
639     }
640 }