Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!mit.eternal-september.org!.POSTED!not-for-mail From: Simon Lewis Newsgroups: comp.lang.javascript Subject: Re: intercept an alert Date: Mon, 12 May 2014 12:29:36 +0200 Organization: Lewis Lines: 32 Message-ID: <8761lb47e7.fsf@gmail.com> References: <862dneogqrcsze3OnZ2dnUVZ_gCdnZ2d@westnet.com.au> <3910370.hJEAF5dPUy@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mit.eternal-september.org; posting-host="1ee1c920522f5180c3b02b9a2b32cdda"; logging-data="12164"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195MCwfgNa6+sC6qX7fwjNInyYoTl0OgDA=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:/IDmZa9pMbjG/Y0de0DpVE8Opzw= sha1:kCsUWjVBlMA4kznzGkZDYFH/y8I= Xref: csiph.com comp.lang.javascript:24139 Thomas 'PointedEars' Lahn writes: > Andrew Poulos wrote: > >> if (!window._alert) { >> window._alert = window.alert; >> } >> >> window.alert = function(msg){ >> if (msg.indexOf('is empty') != -1) { >> return false; >> } else { >> return window._alert.apply(this, arguments); >> } >> }; >> >> Is this the way to go? > > Not quite. You should not augment the host object referred to by “window” > with an “_alert” property (modifying its “alert” property is bad enough, but > I cannot see a better alternative here). Use a variable or a property of > your own object instead. Nonsense. It's perfectly fine to do that. People tag things on to "window" in each and every JS project.