Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: Drop off an if evaluation? Date: Fri, 11 Sep 2020 09:05:05 +0200 Lines: 35 Message-ID: References: <7b1b8132-4b87-4447-b31e-33d542b0529co@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net iY80A6RjF3hC/Fpnz+yDUw2088/fQPGcJTpifuyC33ufI9a0Yt Cancel-Lock: sha1:F06ctc9oR1goZ+BptSilqZ6Rdd8= In-Reply-To: <7b1b8132-4b87-4447-b31e-33d542b0529co@googlegroups.com> Xref: csiph.com comp.lang.javascript:38772 Jonas Thörnvall: > Is there ways to code so that things that will only be true once, never checked again? > > The check dissapear? Maybe something like this: var mycheck = function(x) { console.log('Check still executed'); if(x == true) { mycheck = function(x) { console.log('Not checking any longer'); return 1; } return 1; } else { return 2; } } console.log('Run 1 with false');mycheck(false); console.log('Run 2 with true');mycheck(true); console.log('Run 3 with false');mycheck(false); console.log('Run 4 with true');mycheck(true); console.log('Run 5 with false');mycheck(false); console.log('Run 6 with true');mycheck(true); As soon as mycheck() is called with true as parameter, it replaces itself with another function which will not do any check any more. -- Arno Welzel https://arnowelzel.de