我难以想象现实世界情景,我需要这样做:
function foo() {};
foo.prototype.myFunction = function() { return something; };
不要简单地这样做:
function foo() { this.myFunction = function() { return something; } };
我难以想象现实世界情景,我需要这样做:
function foo() {};
foo.prototype.myFunction = function() { return something; };
不要简单地这样做:
function foo() { this.myFunction = function() { return something; } };
让我们有两例<代码>foo (实际上,作为建筑商,应当将其资本化......)
var myFoo1 = new foo();
var myFoo2 = new foo();
在第一种情况下,<代码>myFunction载于foo
原型,因此,记忆中只存在一种功能。 www.un.org/Depts/DGACM/index_spanish.htm 这两种功能都可出于自己的目的使用,因为它们使用不同的<条码>。
在第二种情况下,每次创建<代码>foo的例时,都会制作一个新的<密码>。 记忆中将出现多个事例。
因此,如果你将物体的方法(或只读成员变量,或只是其他共同点)输入原型,则会节省记忆。 另一方面,这也减缓了成员国的视线——该功能并非直接出现在物体上,而是提升了其原型链。
造成巨大差异的一个很好例子就是,当你需要播下大量“foo”物体时。 原型解决方案将比第二种方案更快、效率更高。
The reason it makes a huge difference in that case, is that in the second example you are creating a new function for every new instance and in the first one all the object share the same function.
真正世界需要利用原型遗产来进行表演的一个很好例子就是图书馆,如 j。 在非属地网络应用中,你可以很容易地在2000年之后结束,并创建更多的对象。 如果每个目标都必须有自己的功能,而不是分享。
There s never a need to do it, but there are some advantages, as well as disadvantages.
一种优势:原型功能由<代码>foo的构造者共同使用。
A disadvantage: the prototyped function has no direct access to variables in the immediate variable scope of the foo
constructor invocations.
施工人员不使用<条码>prototype,而是可以在施工人员中直接分配功能,而不必为每个物体创造新的功能。
You can do it like this...
var foo = (function() {
var myFunction = function() { return something; };
return function foo() { this.myFunction = myFunction; };
})();
This has the same limitation of prototyped functions in that the myFunction
will obviously not be able to access variables in the scope of the constructor.
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.