首页 \ 问答 \ 从Chrome开发者控制台调用JavaScript函数(Call javascript function from chrome developer console)

从Chrome开发者控制台调用JavaScript函数(Call javascript function from chrome developer console)

非常简单的脚本:

function foo(){
    return "bar"
}

console.log( foo() );

安慰:

> bar // sanity test that proves everything's working
> foo(); // this guy is key!
> ReferenceError: foo is not defined

我应该如何调用foo(); 用于调试和实验目的?

这不是一种习惯吗? 我喜欢使用IRB / Rails控制台来验证我的ruby代码,并希望对JavaScript执行相同的操作

http://jsfiddle.net/m2muL/


Very simple script:

function foo(){
    return "bar"
}

console.log( foo() );

console:

> bar // sanity test that proves everything's working
> foo(); // this guy is key!
> ReferenceError: foo is not defined

How should I call foo(); for debugging and experimentation purposes?

Is this not a practise? I love using IRB / Rails Console to verify my ruby code and want to do the same with JavaScript

http://jsfiddle.net/m2muL/


原文:https://stackoverflow.com/questions/23641434
更新时间:2022-06-18 06:06

最满意答案

r'^M?M?M?$'r'^M{0,3}$' 。 因此,您的模式接受'', 'M', 'MM', 'MMM'字符串。

r'M?M?M?$'r'M{0,3}$相同,实际上,它接受所有字符串,因为字符串末尾总是有一个空的部分:

In [21]: pattern = r'M?M?M?$'

In [22]: re.search(pattern, 'A string without capital m at all')
Out[22]: <_sre.SRE_Match object; span=(33, 33), match=''>

r'^M?M?M?$' is the same as r'^M{0,3}$'. So, your pattern accepts '', 'M', 'MM', 'MMM' strings.

r'M?M?M?$' is the same as r'M{0,3}$ and, actually, accepts all strings, since there is always an empty part at the end of the string:

In [21]: pattern = r'M?M?M?$'

In [22]: re.search(pattern, 'A string without capital m at all')
Out[22]: <_sre.SRE_Match object; span=(33, 33), match=''>

相关问答

更多
  • import re regex = ur"\[P\] (.+?) \[/P\]+?" line = "President [P] Barack Obama [/P] met Microsoft founder [P] Bill Gates [/P], yesterday." person = re.findall(regex, line) print(person) 产量 ['Barack Obama', 'Bill Gates'] 正则表达式您的ur"[\u005B1P\u005D.+?\u005B\ ...
  • r'^M?M?M?$'与r'^M{0,3}$' 。 因此,您的模式接受'', 'M', 'MM', 'MMM'字符串。 r'M?M?M?$'与r'M{0,3}$相同,实际上,它接受所有字符串,因为字符串末尾总是有一个空的部分: In [21]: pattern = r'M?M?M?$' In [22]: re.search(pattern, 'A string without capital m at all') Out[22]: <_sre.SRE_Match object; span=(33, 33) ...
  • 如果你想匹配的是字母(包括“国际”字母),你可以使用\p{L} 。 你可以在这里找到关于正则表达式和Unicode的一些信息 。 If all you want to match is letters (including "international" letters) you can use \p{L}. You can find some information on regex and Unicode here.
  • 您的代码用"science"和字母替换text的双字母,然后将字符串传递给multiple_replace ,然后将每个单个字母(包括"science"的字母)替换为相应的字典值。 进行替换的更好方法是将回调传递给sub并使用匹配双字母或单字母的正则表达式。 回调将确定匹配的内容并返回相应的替换。 如果你想坚持使用已有的代码,那么防止"science"的字母被替换的快速方法是将multiple_replace的正则表达式更改为 regex = re.compile("science|(?
  • 这就是你想要的:( 来源 ) re.finditer(pattern, string[, flags]) 返回一个迭代器,通过字符串中RE模式的所有非重叠匹配产生MatchObject实例。 字符串从左到右扫描,并按照找到的顺序返回匹配项。 结果中包含空比赛,除非他们触及另一场比赛的开始。 然后,您可以从MatchObjects中获取开始和结束位置。 例如 [(m.start(0), m.end(0)) for m in re.finditer(pattern, string)] This is wh ...
  • 根据这个数据集,最容易做的事情可能就是将一个量词添加到公开的文件中,例如: /\(+(.+?)\)/ 这样它就可以匹配任何连续数量的开放分值,这些分值将导致您想要捕获的数据,但必须在比赛的下一部分之前至少有一个paren。 这里是关于rubular的例子 。 请注意 :正如我在下面提到的,这将捕获由其他角色分隔的分组中的开放参数(Ridgerider在下面的评论中提供了一个( (stuff))的例子,类似于(1(1) 。 从样本中不清楚这是否是期望的行为 ,但如果不是,则见下文。 假设你不需要捕捉(任何地方 ...
  • 文本的长度和内容都很重要。 例如,正则表达式a+b在包含一百万b的字符串上快速匹配失败,但在包含一百万a s的字符串上更慢。 这是因为在第二种情况下需要更多的回溯。 import timeit x = "re.search('a+b', s)" print timeit.timeit(x, "import re;s='a'*10000", number=10) print timeit.timeit(x, "import re;s='b'*10000", number=10) 结果: 6.85791902 ...
  • 然而,如果你想清除未知字符,你可能想要定义什么是允许的,而不是试图找出所有不可能的东西。 The regex for finding a form feed is \f, however, if you want to weed out unknown characters, perhaps you may want to just define what is allowed, rather than trying to figure out all the possible things that ar ...
  • 您可以使用re.compile()简单地尝试编译正则表达式,如果正则表达式无效,则会抛出re.error 。 try: re.compile(regex) except re.error: # not valid You can simply try to compile the regex using re.compile(), and an re.error will be thrown if the regex is invalid. try: re.compile(rege ...
  • 如果您只寻找最大深度为5,那么您可以使用以下正则表达式 (\((\((\((\((\(\))*\))*\))*\))*\))* 您可以在http://regex101.com/r/zN1sZ2/1预测结果 作为奖励,这里有一些伪造的代码可以用来生成这个字符串 var s = "_", depth = 5; while(depth > 0) { s = s.replace("_", "(\\(_\\))*"); depth--; } s = s.replace("_", ""); 现在,如 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。