super

set attribute with javascript super method [duplicate]

断了今生、忘了曾经 提交于 2019-11-28 12:32:22
Possible Duplicate: Why are my JS object properties being overwritten by other instances Why isn't the attribute "t" changed after setT was called? I would expect "4" as output, but it prints "default". function Car(i) { var id = i; var t = "default"; this.getT = function() { return t; } this.setT = function(p) { t = p; // attribute t isn't changed .. } } function ECar(id) { Car.call(this, id); // super constructor call this.setT = function(p) { // override ECar.prototype.setT.call(this, p); // super call } } ECar.prototype = new Car(); ecar = new ECar(3); ecar.setT(4); alert(ecar.getT()); //

super keyword unexpected here

主宰稳场 提交于 2019-11-28 12:04:30
According to ES6 shorthand initialiser, following 2 methods are same: In ES5 var person = { name: "Person", greet: function() { return "Hello " + this.name; } }; In ES6 var person = { name: "Person", greet() { return "Hello " + this.name; } }; Do the ES6 way is in anyway different from the previous way? If not then using "super" inside them should be also treated as equal, which doesn't hold true, please see below two variaiton: Below works let person = { greet(){ super.greet(); } }; Object.setPrototypeOf(person, { greet: function(){ console.log("Prototype method"); } }); person.greet(); Below

Force base method call

假装没事ソ 提交于 2019-11-28 11:54:17
Is there a construct in Java or C# that forces inheriting classes to call the base implementation? You can call super() or base() but is it possible to have it throw a compile-time error if it isn't called? That would be very convenient.. --edit-- I am mainly curious about overriding methods. There isn't and shouldn't be anything to do that. The closest thing I can think of off hand if something like having this in the base class: public virtual void BeforeFoo(){} public void Foo() { this.BeforeFoo(); //do some stuff this.AfterFoo(); } public virtual void AfterFoo(){} And allow the inheriting

Python 2.7 super() error [duplicate]

本小妞迷上赌 提交于 2019-11-28 11:37:04
This question already has an answer here: super() fails with error: TypeError “argument 1 must be type, not classobj” when parent does not inherit from object 4 answers Trying to create Tkinter window using super(). I get this error: super(Application, self)._ init _(master) TypeError: must be type, not classobj Code: import Tkinter as tk class Application(tk.Frame): def __init__(self, master): super(Application, self).__init__(master) self.grid() def main(): root = tk.Tk() root.geometry('200x150') app = Application(root) root.mainloop() main() Tkinter uses old-style classes. super() can only

Constructor overriding

旧时模样 提交于 2019-11-28 10:42:48
I have a class: class One def initialize; end end I need to create a new class with my own constructor like this: class Two < One def initialize(some) puts some super end end Two.new("thing") but when I launch the code, I got an error: thing test.rb:10:in `initialize': wrong number of arguments (1 for 0) (ArgumentError) super in this case (without parentheses) is a special form. It calls the superclass method with the original params. Instead try calling super() 来源: https://stackoverflow.com/questions/2570428/constructor-overriding

Why do we need super keyword to call default interface methods?

非 Y 不嫁゛ 提交于 2019-11-28 09:21:51
问题 In the below code when I am having a class implementing two interfaces with same default method signature it ask me to override it. but in the overriden method why I have to use super keyWord to call the default method. package practice; interface interA{ public default void AImp(){ System.out.println("Calling Aimp from interA"); } } interface interB{ public default void AImp(){ System.out.println("Calling Aimp from interB"); } } public class Practice implements interA,interB { public static

python, inheritance, super() method

元气小坏坏 提交于 2019-11-28 09:17:44
问题 I'm new to python, I have the code below which I just can't get to work:- This is inheritance, I have a circle base class and I inherit this within a circle class (just single inheritance here). I understand the issue is within the ToString() function within the circle class, specifically the line, text = super(Point, self).ToString() +.. which requires at least a single argument, yet I get this: AttributeError: 'super' object has no attribute 'ToString' I know super has no ToString attribute

Python super and setting parent class property

自作多情 提交于 2019-11-28 08:13:38
I'm having a really strange problem with Python super() and inheritance and properties. First, the code: #!/usr/bin/env python3 import pyglet import pygame class Sprite(pyglet.sprite.Sprite): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.rect = pygame.Rect(0, 0, self.width, self.height) self.rect.center = self.x, self.y @property def x(self): return super().x @x.setter def x(self, value): super(Sprite, self.__class__).x.fset(self, value) self.rect.centerx = value @property def y(self): return super().y @y.setter def y(self, value): super(Sprite, self.__class__).y

Emulate super in javascript

岁酱吖の 提交于 2019-11-28 06:22:26
Basically is there a good elegant mechanism to emulate super with syntax that is as simple as one of the following this.$super.prop() this.$super.prop.apply(this, arguments); Criteria to uphold are : this.$super must be a reference to the prototype. i.e. if I change the super prototype at run-time this change will be reflected. This basically means it the parent has a new property then this should be shown at run-time on all children through super just like a hard coded reference to the parent would reflect changes this.$super.f.apply(this, arguments); must work for recursive calls. For any

super() in constructor

老子叫甜甜 提交于 2019-11-28 06:21:27
I'm reading through some code. In the constructor it has super() but the class implements interface which of course doesn't have a constructor. So which super() it is referring to? public class BoundingBox implements IBoundingVolume { public BoundingBox() { super(); mTransformedMin = new Number3D(); mTransformedMax = new Number3D(); mTmpMin = new Number3D(); mTmpMax = new Number3D(); mPoints = new Number3D[8]; mTmp = new Number3D[8]; mMin = new Number3D(); mMax = new Number3D(); for(int i=0; i<8; ++i) { mPoints[i] = new Number3D(); mTmp[i] = new Number3D(); } } public interface IBoundingVolume