what javascript prototype.constructor for?

Possible Duplicate: How does JavaScript .prototype work? Here is the inheritance structure I setup for testing: function A() { this.a = 1; } function B() { this.b = 2; } B.prototype = new A(); //B.prototype.constructor = B; Below is what I tried in Chrome's JavaScript Console: >var b = new B; >b instanceof A true >B.prototype.constructor function A() { this.a =

什么JavaScript的prototype.constructor的?

可能重复: JavaScript .prototype如何工作? 这里是我为测试设置的继承结构: function A() { this.a = 1; } function B() { this.b = 2; } B.prototype = new A(); //B.prototype.constructor = B; 以下是我在Chrome的JavaScript控制台中尝试的内容: >var b = new B; >b instanceof A true >B.prototype.constructor function A() { this.a = 1; } 我的问题是设置B.prototype.constructor =

JavaScript prototype delegation in function

This question already has an answer here: How does JavaScript .prototype work? 21 answers What you have is a constructor function that has m in its prototype. var func = function (){}; func.prototype = {m:9}; console.log( func.prototype.m ); // That logs 9 The prototype is assigned not to the function itself but to instances created by this function: var f = new func(); console.log( f.m

JavaScript原型委托功能

这个问题在这里已经有了答案: JavaScript .prototype如何工作? 21个答案 你有一个构造函数,它的原型中有m 。 var func = function (){}; func.prototype = {m:9}; console.log( func.prototype.m ); // That logs 9 原型不是分配给函数本身,而是分配给由此函数创建的实例: var f = new func(); console.log( f.m ); // That also logs 9 这是你的m是。 为此还记录9 func.m 你必须在Function.prototype有m ,

Add value using prototype in function instance

This question already has an answer here: How does JavaScript .prototype work? 21 answers It should be a prototype of the constructor function, not the object this function produces: a.prototype.three = 3; You can't access object's prototype with the prototype key, because prototype reference is not exposed like this. You could do it using __proto__ property though, but this is de

在函数实例中使用原型添加值

这个问题在这里已经有了答案: JavaScript .prototype如何工作? 21个答案 它应该是构造函数的原型,而不是该函数产生的对象: a.prototype.three = 3; 您不能使用prototype键访问对象的原型,因为原型引用不会像这样暴露。 尽管你可以使用__proto__属性来做到这点,但是这已经被弃用了。 如果您需要获取对象的原型,则可以使用Object.getPrototypeOf方法: Object.getPrototypeOf(j) === a.prototype; // true 这里

Function object prototype

This question already has an answer here: How does JavaScript .prototype work? 21 answers A prototype is nothing more than an object from which instances inherit properties. So, funcObj is an instance of another prototype (the one of Function ) from which it has inherited all the properties. Also, it has for itself a prototype on which you can bind whatever you want and that prototype wil

函数对象原型

这个问题在这里已经有了答案: JavaScript .prototype如何工作? 21个答案 原型只不过是实例继承属性的对象。 因此, funcObj是另一个原型( Function的一个)的实例,它从中继承了所有的属性。 另外,它本身也有一个prototype ,你可以在其上绑定任何你想要的原型,并且一旦你调用它来构造funcObj新实例,就会使用原型(也就是说,当你将它和new keywork一起调用时,就像new funcObj() )。 因此, funcObj没有叫做gr

understanding Prototype in javascript

Possible Duplicate: How does JavaScript .prototype work? Coming from Java background, I'm trying to understand javascript. Please let me know if these are right. Like in java, there is a supreme Object, from which all other objects inherit. The prototype property is like a pointer that points to the parent object (classes in java) For "Object" object, the prototype is nu

了解JavaScript中的原型

可能重复: JavaScript .prototype如何工作? 来自Java背景,我想了解JavaScript。 请让我知道这些是否正确。 像在java中一样,有一个最高级对象,所有其他对象都从中继承。 prototype属性就像一个指向父对象的指针(java中的类) 对于“对象”对象,原型为空。 原型属性的值是表示对象命名的字符串,并不像C中的指针。指针概念使用隐藏属性[[PROTOTYPE]]实现,该属性在脚本中无法访问。 我使用node.js而不是浏览

How to handle javascript object

This question already has an answer here: How does JavaScript .prototype work? 21 answers Can not undestand whole lots of things that you have written. But the problem is ver clear. "this", you are expecting to be your method, but you have to very careful of this as it changes context based upon where you are executing it. If I simplyfy your code, its an example of module patte

如何处理javascript对象

这个问题在这里已经有了答案: JavaScript .prototype如何工作? 21个答案 无法打开你写过的很多东西。 但问题是明确的。 “this”,你期望成为你的方法,但是你必须非常小心,因为它会根据执行的位置来改变上下文。 如果我简单地解释你的代码,它就是一个模块模式的例子,它应该如下。 var moduleExample = (function () { // private variables and functions var privateVar = 'bar'; // constructor

What is the word prototype used for in Javascript?

This question already has an answer here: How does JavaScript .prototype work? 21 answers The prototype chain is how you associate a method with a given type instead of just a specific instance of an object. It's beneficial for performance reasons since you don't have to redefine the method for every instance since it's defined once at the type level. Example using prototype:

Javascript中使用的原型是什么?

这个问题在这里已经有了答案: JavaScript .prototype如何工作? 21个答案 原型链是您如何将方法与给定类型关联,而不仅仅是某个对象的特定实例。 这对性能有利,因为您不必为每个实例重新定义方法,因为它在类型级别上定义了一次。 使用原型的示例: var car = function(){ }; car.prototype.start= function(){ }; var myCar = new car();//all car objects will have the start function defined. 没有使用原型的

Prototype property throwing undefined

This question already has an answer here: How does JavaScript .prototype work? 21 answers The problem of confusion is that the word prototype kind of has two meanings. 1. Function property . Any function can have a prototype property, which is an object. In your case Test.prototype = { sayHello: function() {} } Properties of this object become inherited properties and methods of th

原型属性抛出undefined

这个问题在这里已经有了答案: JavaScript .prototype如何工作? 21个答案 混淆的问题是, prototype这个词有两个含义。 1.功能属性 。 任何函数都可以有一个prototype属性,它是一个对象。 在你的情况 Test.prototype = { sayHello: function() {} } 此对象的属性成为用此构造函数构造的对象的继承属性和方法: var z = new Test(); 现在z有一个方法属性sayHello ,你可以在Test.prototype对象的帮助下配置它

How to make a function to go after an element

This question already has an answer here: How does JavaScript .prototype work? 21 answers 你可以使用原型来实现它// `getElementById` returns a `Element` object so extend it's prototype Element.prototype.someFunction = function(){ // this.somethig } document.getElementById("element").someFunction(); Element.prototype.someFunction = function() { console.log(this.value) } document.getE

如何制作一个功能去追逐元素

这个问题在这里已经有了答案: JavaScript .prototype如何工作? 21个答案 你可以使用原型来实现它// `getElementById` returns a `Element` object so extend it's prototype Element.prototype.someFunction = function(){ // this.somethig } document.getElementById("element").someFunction(); Element.prototype.someFunction = function() { console.log(this.value) } document.getElementById("element"

what is the use of prototype property in javascript?

Possible Duplicate: How does JavaScript .prototype work? What is the use of prototype property when properties can be added to object even without it? var o = {}; o.x = 5; o.y = test; test = new function(){ alert("hello"); }; Adding a method / property to a prototype is adding it to all objects with that prototype in their prototype chain. Your code is adding a method/property to a sing

在JavaScript中使用prototype属性有什么用?

可能重复: JavaScript .prototype如何工作? 当属性可以添加到对象时,甚至没有它时,prototype属性的用法是什么? var o = {}; o.x = 5; o.y = test; test = new function(){ alert("hello"); }; 将一个方法/属性添加到原型将其添加到原型链中具有该原型的所有对象。 您的代码正在向单个实例添加方法/属性。 要使用原型,您需要使用新建来创建对象。 如果通过对象文字创建对象,则不会指定该对象的原型,据我所知