Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #20335

Re: Identifying a regex

Message-ID <4497153.IWULeidUyA@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-06-18 21:39 +0200
Subject Re: Identifying a regex
Newsgroups comp.lang.javascript
References (1 earlier) <3c26ff4d-3b91-4784-bea9-20740208b338@x4g2000yqk.googlegroups.com> <kpmu20$5q5$1@news.albasani.net> <f623b8ea-0bf3-429d-b04b-903627edfa1e@a8g2000yqp.googlegroups.com> <2138020.VnviE1jULI@PointedEars.de> <kpq833$o40$1@news.albasani.net>

Show all headers | View raw


Stefan Weiss wrote:

> On 2013-06-18 02:13, Thomas 'PointedEars' Lahn wrote:
>> In the case of references to RegExp instances, though, where inheriting
>> from their prototype does not make sense and so all pertinent objects
>> have [[Class]] "RegExp", in JSX:regexp.js I have switched from comparison
>> [[against the “constructor” property value to jsx.object.getClass() for
>> the next revision, for cross-view referencing.
> 
> For reference:
> 
>   var _getClass = (function () {
>     var _toString = ({}).toString;
> 
>     return function (obj) {
>       return (_toString.call(obj)
>         .match(/^\s*\[object\s+(\S+)\s*\]\s*$/) || [, ])[1];
>     };
>   }());
> 
> 
http://pointedears.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Fobject.js
> 
> That would correspond to option (C) in my original question.

Yes.
 
> The old comparison method in your regexp.js (rev 361) is not the same as
> option (B), however: comparing the constructor property directly with
> RegExp does not work across frames, but comparing constructor.name with
> "RegExp" does (as long as nobody messed with the constructor directly).

I am not convinced that constructor.name is interoperable in the first 
place.  The ECMAScript Support Matrix, Version 2, contains a testcase for 
Function.prototype.name that has been recently run (by someone else – thank 
you) to fail in JavaScript 1.8.6 and JScript 10.0.16578.  But that might be 
due to “name” being a property of Function instances only in those 
implementations.  I shall modify that testcase accordingly.

<http://PointedEars.de/es-matrix/?filter=Function.prototype.name#features-table>

That said, neither Function.prototype.name nor functionInstance.name are 
specified in the ECMAScript Language Specification, 5.1 Edition, §15.3, so 
they are very likely not interoperable.  Which is why there is

/**
 * Returns the name of a function
 *
 * @param {Function|String} aFunction
 * @return {string}
 *   The name of a function if it has one; the empty string otherwise.
 */
jsx.object.getFunctionName = function (aFunction) {
  /* Return the empty string for null or undefined */
  return (aFunction != null
           && typeof aFunction.name != "undefined" && aFunction.name)
    || (String(aFunction).match(/\s*function\s+([A-Za-z_]\w*)/) || [, ""])
[1];
};
 
> In my specific case, I can see both methods working equally well.  […]

I don't.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-17 01:47 +0200
  Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-16 19:30 -0700
    Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-17 14:05 +0200
      Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-17 16:16 -0700
        Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-18 02:13 +0200
          Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-18 20:14 +0200
            Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-18 21:39 +0200
              Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-18 23:58 +0200
                Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-25 22:05 +0200
                Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-25 16:59 -0700
                Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-26 23:47 +0200
              Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-23 20:01 +0200
        Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-18 00:40 -0700
          Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-18 10:39 +0200
            Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-18 19:32 -0700
              Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-19 14:05 +0200
                Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-19 20:24 -0700
                Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-20 12:27 +0200
                Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-20 18:08 -0700
  Re: Identifying a regex JJ <duh@nah.meh> - 2013-06-17 13:58 +0700
    Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-17 14:11 +0200
      Re: Identifying a regex JJ <duh@nah.meh> - 2013-06-18 12:46 +0700
        Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-18 20:17 +0200
  Re: Identifying a regex Andreas Bergmaier <andber93@web.de> - 2013-06-18 21:14 +0200

csiph-web