prototype-programming

How to represent Javascript object creation with an UML class diagram?

 ̄綄美尐妖づ 提交于 2021-02-17 22:00:27
问题 I'm having some trouble drawing an accurate UML Class diagram for my JavaScript APP. I've read several UML reference resources, but still didn't find an answer for my situation, since all the examples are based on the classical inheritance and class model of C++/Java. I want to represent the creation of a custom JavaScript object with a constructor function and extension of it's prototype object, which is quite different from C++/Java class instantiation. How would you represent this

Accessing properties from prototype functions

心已入冬 提交于 2021-02-10 05:43:27
问题 I'm reusing an old application (a game) so it's possible to run several games at ones. By that reason I've changed the properties to "this.propery", which are used everywhere in my application. However, the only prototype function that can access the properties is "startGame". I have tried both "this.bricks" and "Game.bricks", but both are undefined when trying to reach them in any other function that "startGame". Any tips for me? var game = new Game(); game.startGame(); Game = function(){

proto inheritance from ES6 class [duplicate]

蓝咒 提交于 2020-11-28 02:41:33
问题 This question already has an answer here : Is it possible to inherit old-style class from ECMAScript 6 class in JavaScript? (1 answer) Closed last month . I have an old codebase full of subclasses of a some external class, using prototypal inheritance. Recently, this external class has been ported to an ES6 class, but also has new features I'd like to use. Prototypal inheritance doesn't work anymore, and I'm wondering if it's possible to make it work even if it's with some ugly hack. This is

proto inheritance from ES6 class [duplicate]

旧时模样 提交于 2020-11-28 02:41:24
问题 This question already has an answer here : Is it possible to inherit old-style class from ECMAScript 6 class in JavaScript? (1 answer) Closed last month . I have an old codebase full of subclasses of a some external class, using prototypal inheritance. Recently, this external class has been ported to an ES6 class, but also has new features I'd like to use. Prototypal inheritance doesn't work anymore, and I'm wondering if it's possible to make it work even if it's with some ugly hack. This is

What does “the prototype belongs to the class not the instance” mean in javascript?

寵の児 提交于 2020-01-29 09:55:56
问题 I asked the question: Why cant I declare a constructor instantiate an object and then access the prototype? And you can see that I have marked the answer. I understand the response but Im a bit confused as to what he means by: The prototype belongs to the class, not the instance: Does this mean that javascript has a class in this example? I thought javascript was classless? It only has function constructors... At what point does a function constructor become a class? Is it when you add other

What does “the prototype belongs to the class not the instance” mean in javascript?

谁说胖子不能爱 提交于 2020-01-29 09:53:07
问题 I asked the question: Why cant I declare a constructor instantiate an object and then access the prototype? And you can see that I have marked the answer. I understand the response but Im a bit confused as to what he means by: The prototype belongs to the class, not the instance: Does this mean that javascript has a class in this example? I thought javascript was classless? It only has function constructors... At what point does a function constructor become a class? Is it when you add other

Javascript prototype and __proto__ and getPrototypeOf issue

独自空忆成欢 提交于 2020-01-24 07:38:42
问题 I have a simple class in javascript: function foo() { this.bar = "bar"; } var test = new foo; console.log(foo.prototype,foo.__proto__) /*output: foo { constructor: function foo() { __proto__: Object } , function Empty() {} */ console.log(test,test.prototype,test.__proto__,test.__proto__.__proto__) /*output: foo { bar: "bar" __proto__: foo } , undefined , foo { constructor: function foo() { __proto__: Object } , Object { ... } */ What i dont understand: At the first log the foo.prototype had

The disadvantages of JavaScript prototype inheritance, what are they?

风流意气都作罢 提交于 2020-01-11 20:01:30
问题 I recently watched Douglas Crockford's JavaScript presentations, where he raves about JavaScript prototype inheritance as if it is the best thing since sliced white bread. Considering Crockford's reputation, it may very well be. Can someone please tell me what is the downside of JavaScript prototype inheritance? (compared to class inheritance in C# or Java, for example) 回答1: Things I miss when sub-classing an existing object in Javascript vs. inheriting from a class in C++: No standard (built

javascript prototype declaration

ぃ、小莉子 提交于 2020-01-06 13:31:04
问题 There are two pieces of codes. Why is the first one correct but the second one incorrect? What's wrong with this.prototype ? function Person(name, age, job){ this.name = name; this.age = age; this.job = job; if (typeof this.sayName != "function"){ Person.prototype.sayName = function(){ alert(this.name); }; } } function Person(name, age, job){ this.name = name; this.age = age; this.job = job; if (typeof this.sayName != "function"){ this.prototype.sayName = function(){ alert(this.name); }; } }

Reason behind using 'instanceof function() {}'?

血红的双手。 提交于 2020-01-01 04:11:05
问题 On Mozilla Developer Center, there is a page about the Function.prototype.bind function and provides a compatibility function for browsers which do not support this function. However, when analyzing this compatibility code I cannot find out why they use instanceof nop . nop has been set to function() {} . What part of the ECMA specification on bind does this correspond with? And what variables are an instance of function() {} ? The following returns false , so I don't completely know what it