When function returns result and when function in JavaScript

I see a lot that function returns NOT the result but the function. The example below shows that function getWindow returns function. Why it can't just return variable "win"? When I return result and when function? Thank you. var A = function(){}; A.prototype= { getWindow : function() { var win = new B.window(); return ( this.getWindow = fun

当函数返回结果和当在JavaScript中的函数

我看到很多函数返回的结果不是函数。 下面的例子显示函数getWindow返回函数。 为什么它不能只是返回变量“赢”? 当我返回结果和何时功能? 谢谢。 var A = function(){}; A.prototype= { getWindow : function() { var win = new B.window(); return ( this.getWindow = function() { return win; })(); } } 此代码与您的

Are local function declarations cached?

function A() { function B() { ... } B(); } Is function B created every time A is called or is there some caching on it. Is not making it local like : function A() { B(); } function B() { ... } A significant performance improvement? Is it valid to do this a style choice? ( B in this case is just a helper function for A .) or should the second be favou

本地函数声明是否缓存?

function A() { function B() { ... } B(); } 每次调用A都会创建函数B或者是否存在一些缓存。 不是让它像本地一样: function A() { B(); } function B() { ... } 显着的性能改进? 这是一个风格选择是否有效? (在这种情况下, B只是A的助手函数),还是第二个应该受到速度的青睐? 为了可读性,是否应该使用或避免使用这种风格? 基准。 看起来像FF4为本地情况内联B ,

enter to trigger button click?

I have an html form like this: <form name="f1"> <center> <strong>Search VMs:</strong> <input id='vms' name="word" type="text" size="50" placeholder="Name or IP, space delimited, partial name OK." autofocus autocomplete="off" pattern=".{3,}" required title="3 chars minimum" /> in <select name="vc" id='whichvc'> <option value="all" selected="selected"

进入触发按钮点击?

我有这样的HTML表单: <form name="f1"> <center> <strong>Search VMs:</strong> <input id='vms' name="word" type="text" size="50" placeholder="Name or IP, space delimited, partial name OK." autofocus autocomplete="off" pattern=".{3,}" required title="3 chars minimum" /> in <select name="vc" id='whichvc'> <option value="all" selected="selected">all VC

Bind onclick to enter key

I have a small search box in a content editor web part on my SharePoint site. The user inputs some text into a text box and then has to CLICK an image which serves as the submit button (clicking the image loads the javascript function onclick.) This is pretty terrible as you cannot press enter to search. Is there any way to set up the image or onClick() so that it detects Enter being pressed

绑定onclick输入密钥

我的SharePoint网站上的内容编辑器Web部件中有一个小型搜索框。 用户在文本框中输入一些文本,然后点击一个图像作为提交按钮(单击图像加载javascript函数onclick。) 这是非常可怕的,因为你无法按回车进行搜索。 有没有什么办法设置图像或onClick(),以便它检测到按下按钮,就像正常的提交按钮? 谢谢你的帮助 对于onclick()不,它不是,但你可以使用onkeyup() : yourTextField.onkeyup=function(){ if(event.ke

How to disable the enter button from triggering the onkeyup event?

In my asp.net solution, I have a text input box and a search button. There is a onkeyup jquery event on the text input field so it automatically clicks the search button when the user presses a key. You can also manually click the button. But what I noticed is that if you are typing, and then you press ENTER key, it will trigger the on onkeyup event. How can I disable the function from occur

如何禁用输入按钮来触发onkeyup事件?

在我的asp.net解决方案中,我有一个文本输入框和一个搜索按钮。 在文本输入字段中有一个onkeyup jquery事件,所以当用户按下某个键时它会自动点击搜索按钮。 您也可以手动点击按钮。 但我注意到,如果您正在键入,然后按下ENTER键,则会触发onkeyup事件。 如何按下ENTER键禁用该功能,或者可能检测到是否为ENTER键,然后是否有if语句或某事。 另一件事是,如果输入框中的文本出现问题,我会显示一个警告消息框。 然后,

How to capture enter key press of?

In my HTML page, I had a textbox for user to input keyword for searching. When they click the search button, the JavaScript function will generate a URL and run in new window. The JavaScript function work properly when the user clicks the search button by mouse, but there is no response when the user presses the ENTER key. function searching() { var keywordsStr = docum

如何捕捉输入按键的?

在我的HTML页面中,我有一个供用户输入关键字进行搜索的文本框。 当他们点击搜索按钮时,JavaScript函数将生成一个URL并在新窗口中运行。 当用户通过鼠标点击搜索按钮时JavaScript功能正常工作,但当用户按下ENTER键时没有响应。 function searching() { var keywordsStr = document.getElementById('keywords').value; var cmd ="http://XXX/advancedsearch_result.asp?language=ENG&am

How do I use the Enter key as an event handler (javascript)?

im trying to make my own chat... so i have an input text field, the submit button, isn't even submit, its just a button.... so when the enter key is pressed, i need the value of the input field to appear in my textarea (which is readonly)... well look.. make long story short, i just want a basic enter key event handler, i know it works perfectly with submit buttons cus you don't need to

如何将Enter键用作事件处理程序(javascript)?

即时尝试做我自己的聊天...所以我有一个输入文本字段,提交按钮,甚至不提交,它只是一个按钮....所以当按下输入键,我需要的价值输入字段出现在我的textarea(这是只读)... 看看..长话短说,我只是想要一个基本的enter键事件处理程序,我知道它与提交按钮cus完美的工作,你不需要编程任何东西,它的默认值。 但我的按钮是type =“button”....所以当你按下输入什么都没有发生......我怎么通过按回车触发我的按钮? 您可以使

Unable to save copy of "count' within an IIFE function

So I have a global var called count which changes from 0 to 4 in between two function declarations (see myFuncs array). I want to create a closure and save a copy of count of 0 for the 1st function and 4 in the 2nd function. Somehow, even though I'm using IIFE (Immediately Invoked Function Expressions) to create new lexical scope and saving the copy of count with (as j), they are still bo

无法在IIFE功能中保存“count”的副本

所以我有一个名为count的全局变量,它在两个函数声明之间从0到4变化(请参阅myFuncs数组)。 我想创建一个闭包,并保存第一个函数的计数为0和第二个函数的计数为4的副本。 不知何故,即使我正在使用IIFE(立即调用的函数表达式)来创建新的词法作用域并以(作为j)保存计数副本,它们仍然指向count = 4,因此,当函数执行时,第一次和第二次功能都打印出我的价值:4“两次,当我预期: “我的价值:0”“我的价值:4” var myFu

Why a nested IIFE is not creating closure?

I'm reading this resource trying to understand how closure works in Javascript. I understood that every time a function is called outside its normal lexical scope, it creates closure, being able to access the enclosing function variables and using them to store state. This works in my_module.incrCounter(); below (which keeps increasing the counter), but why it doesn't work in my_modu

为什么嵌套的IIFE不创建闭包?

我正在阅读这个资源,试图了解在Javascript中闭包是如何工作的。 我明白,每当函数被调用超出其正常的词法范围时,它就会创建闭包,能够访问封闭函数变量并使用它们来存储状态。 这适用于my_module.incrCounter(); 下面(它不断增加计数器),但为什么它不能在my_module.incrLocalCounter(); ,每次都会返回1? 如果不是里面的IIFE incrLocalCounter创建关闭了local_counter ? var my_module = (function tlModule(){

JavaScript Dynamic Closure Scope

I am running into an issue with closures and want to confirm a suspicion. I am trying to give a function access to a scope outside of where it was originally defined. For example the following code block works as I would expect. (function(){ function Outer () { var test = "closure access"; return function Inner () { alert(test); }; }; // call o

JavaScript动态关闭范围

我遇到了一个关闭问题,并想确认一个怀疑。 我试图给一个函数访问它最初定义的范围之外的范围。 例如下面的代码块就像我期望的那样工作。 (function(){ function Outer () { var test = "closure access"; return function Inner () { alert(test); }; }; // call outer then inner Outer()(); }()); 当运行字符串“闭包访问”时会收到警报。 但是,如果内部函数定