admin管理员组

文章数量:1317909

I find a point:

var example = /1/._ ;

It can be accept by the interpreter of chrome or Firefox ,and it always return undefined.

But I don't understand why, is ._ a special usage in regular expression? Or is there something else I don't know?

I have searched in Google, but get nothing.

I find a point:

var example = /1/._ ;

It can be accept by the interpreter of chrome or Firefox ,and it always return undefined.

But I don't understand why, is ._ a special usage in regular expression? Or is there something else I don't know?

I have searched in Google, but get nothing.

Share Improve this question edited Aug 24, 2013 at 10:56 Denys Séguret 383k90 gold badges810 silver badges775 bronze badges asked Aug 24, 2013 at 10:39 kamiakamia 314 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 11

_ is a valid name for a property :

IdentifierStart ::

UnicodeLetter

$

_

\ UnicodeEscapeSequence

As there is no property with this name, you just get undefined. There's nothing specific to regular expression here : there's rarely a property with this name unless you define it or import underscore.js (then it's not on regexes, just on window).

You would have get the same result with

var example = /1/.abracadabra;

or

var example = ({}).π;

Let's break it down:

var example = /1/            .                                                 _;
              ^ regex object ^ dot (meaning, accessing a method of a property) ^ attempt to access a property named "_".

Since _ is a property that doesn't exist, you'll get undefined every time.

Much like you would with

var example = document.somethingThatDoesntExist;

本文标签: What doesmean in javascriptStack Overflow