#15582 closed defect (invalid)
this.inherited does not work for dojo.extend
Reported by: | tanneman | Owned by: | Eugene Lazutkin |
---|---|---|---|
Priority: | undecided | Milestone: | tbd |
Component: | Core | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
dojo.declare('test.Father', null, { constructor: function() { forcare.fatherCtorCount++; }, getName: function() { return 'father'; } }); dojo.extend(test.Father, { getName : function() { return 'god' + this.inherited('getName', arguments); } }); var godfather = new test.Father(); assertEquals('godfather', godfather.getName());
See script above. I also tried it with extend from lang and the extend from the class itself. All possibilities from (http://dojotoolkit.org/reference-guide/1.7/dojo/declare.html#extend) do not work.
Change History (5)
comment:1 Changed 9 years ago by
Component: | General → Core |
---|---|
Owner: | set to Eugene Lazutkin |
Status: | new → assigned |
comment:2 Changed 9 years ago by
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
comment:3 Changed 9 years ago by
I don't want to subclass it, I want to change the Father class. So everywhere the Father class is used it will return a different name. ('im not always
Also, the example suggests that extend should work with inherited. Should this work or not? If so, this is still a valid bug.
comment:4 Changed 9 years ago by
So, there's only one class, and yet you are trying to call this.inherited()? That doesn't make sense. this.inherited() refers to the superclass.
comment:5 Changed 9 years ago by
agreed w/ bill upon reading. You are wanting to monkey patch in without creating a subclass. inherited() is for superclasses. If you want to monkey do something like:
var Father = declare(null, { getName: function(){ return "dante"; } }); var oldGetName = Father.prototype.getName; Father.prototype.getName = function(){ return "monkeydin:" + oldGetName.apply(this, arguments); }
Looks like the docs in the page linked are actually pretty clear about this. From the page:
require(['dojo/_base/declare'], function(declare){ var A = declare(null, { m1: function(){ // ... } }); A.extend({ m1: function(){ // this method will replace the original method // ... }, m2: function(){ // ... } }); var x = new A(); a.m1(); a.m2(); });
There is also a longer section showing the effect of calling .extend from a subclass, and so on.
+invalid/wontfix
I misread this at first... you want the second getName() to call the first one? In that case you are really asking to make a subclass of Father. The way to do that is: