最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What does ._ mean in javascript? - Stack Overflow

programmeradmin1浏览0评论

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;
发布评论

评论列表(0)

  1. 暂无评论