javabind.js revision 1336:efb5f54092ed
161452Sdfr/* 261452Sdfr * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 361452Sdfr * 461452Sdfr * Redistribution and use in source and binary forms, with or without 561452Sdfr * modification, are permitted provided that the following conditions 661452Sdfr * are met: 761452Sdfr * 861452Sdfr * - Redistributions of source code must retain the above copyright 961452Sdfr * notice, this list of conditions and the following disclaimer. 1061452Sdfr * 1161452Sdfr * - Redistributions in binary form must reproduce the above copyright 1261452Sdfr * notice, this list of conditions and the following disclaimer in the 1361452Sdfr * documentation and/or other materials provided with the distribution. 1461452Sdfr * 1561452Sdfr * - Neither the name of Oracle nor the names of its 1661452Sdfr * contributors may be used to endorse or promote products derived 1761452Sdfr * from this software without specific prior written permission. 1861452Sdfr * 1961452Sdfr * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 2061452Sdfr * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 2161452Sdfr * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2261452Sdfr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 2361452Sdfr * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 2461452Sdfr * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2561452Sdfr * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 2661452Sdfr * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27116192Sobrien * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28116192Sobrien * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29116192Sobrien * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3061452Sdfr */ 3161452Sdfr 3261452Sdfr// bind on a Java method 3361452Sdfr 34129878Sphk// #javascript "bind" function 3561452Sdfrvar bind = Function.prototype.bind; 3661452Sdfr 3776827Salfred// Java console object 3879339Sjhbvar console = java.lang.System.console(); 3961452Sdfr 40173573Sjhb// arguments "this" and prompt string of Console.readLine method are bound 41173573Sjhbvar readName = bind.call(console.readLine, console, "Your name: "); 42119288Simp 43119288Simp// Now call it like a function that takes no arguments! 4461452Sdfrprint("Hello,", readName()); 4561452Sdfr