J
jacobstr
I've noticed Object.extend used in a few different ways and I'm having
trouble distinguishing why certain usages apply to a given situation.
[1] On line 804 Ajax.Base is defined as follows:
Ajax.Base = function() {};
Ajax.Base.prototype = {
setOptions: function(options) { <...>
[2] Now later on line 821:
Ajax.Request = Class.create();
<...>
Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
_complete: false, <...>
[3] Preceding that on lines 636 and 664 respectively we have:
Object.extend(Hash, {
toQueryString: function(obj) {
Object.extend(Hash.prototype, {
_each: function(iterator) {
for (var key in this) { <...>
[4] on line 664
var Enumerable = {
each: function(iterator) {
<...>
Object.extend(Enumerable, {
map: Enumerable.collect,
[1] Seems to be going about things in a traditional manner. No class
create(). What exactly is the point of class.create()? It seems highly
redundant.
[2] There's the assignment operator and Object.extend. Would
Object.extend(Ajax.Request.prototype,new Base());
Object.extend(Ajax.Request.prototype, { ... } );
do the same thing?
[3] I'm not sure when / when not to use the prototype keyword ...
actually I don't know what it's for at all! In this example it does it
both ways. What's the difference? Similar situation with [4] and the
illustratory alternative I presented in [2]. Would Ajax.Request
( without .prototype) be correct? Or would that be broken somehow? I
wasted some time experimenting in Firefox with this but Javascript is
pretty fluffy and things like this tend to slip by ~kind of~ working.
Clarification would be greatly appreciated.
trouble distinguishing why certain usages apply to a given situation.
From 1.5.0 prototype.js
[1] On line 804 Ajax.Base is defined as follows:
Ajax.Base = function() {};
Ajax.Base.prototype = {
setOptions: function(options) { <...>
[2] Now later on line 821:
Ajax.Request = Class.create();
<...>
Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
_complete: false, <...>
[3] Preceding that on lines 636 and 664 respectively we have:
Object.extend(Hash, {
toQueryString: function(obj) {
Object.extend(Hash.prototype, {
_each: function(iterator) {
for (var key in this) { <...>
[4] on line 664
var Enumerable = {
each: function(iterator) {
<...>
Object.extend(Enumerable, {
map: Enumerable.collect,
[1] Seems to be going about things in a traditional manner. No class
create(). What exactly is the point of class.create()? It seems highly
redundant.
[2] There's the assignment operator and Object.extend. Would
Object.extend(Ajax.Request.prototype,new Base());
Object.extend(Ajax.Request.prototype, { ... } );
do the same thing?
[3] I'm not sure when / when not to use the prototype keyword ...
actually I don't know what it's for at all! In this example it does it
both ways. What's the difference? Similar situation with [4] and the
illustratory alternative I presented in [2]. Would Ajax.Request
( without .prototype) be correct? Or would that be broken somehow? I
wasted some time experimenting in Firefox with this but Javascript is
pretty fluffy and things like this tend to slip by ~kind of~ working.
Clarification would be greatly appreciated.