Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : If observable = new can.Observe(foo); then Chrome shows that observable is a Constructor and can be confusing

$
0
0
Ok, I did some more research, with the code and output:


var observable = new can.Observe({});

console.log(observable.__proto__ === can.Observe.prototype);

console.log(observable.__proto__.__proto__ === can.Construct.prototype);

console.log(observable.__proto__.__proto__.__proto__ === Object.prototype);

console.log(observable.__proto__.__proto__.__proto__.__proto__ === null);

console.log(can.Observe);
console.log(can.Construct);
console.log(Object);

Output:

true 
true
true 
true 
function Constructor() {
                // All construction is actually done in the init method.
                if (!initializing) {
                    return this.constructor !== Constructor && arguments.length ?
                    // We are being called without `new` or we are extending.
                    arguments.callee.extend.apply(arguments.callee, arguments) :
                    // We are being called with `new`.
                    this.constructor.newInstance.apply(this.constructor, arguments);
                }
            } 
function () {
        if (arguments.length) {
            return can.Construct.extend.apply(can.Construct, arguments);
        }
    } 
function Object() { [native code] } 



and it came down to this:

1. can is an object, and has many properties.

2. Of these properties, one is a property "Observe", and we refer to it by can.Observe, and this property points to a function that's named "Constructor"

3. of these properties (of the can object), another property "Construct", which we refer to it by can.Construct, points to another function which has no name -- it is an anonymous function.

4. and finally, the most bottom base class is Object... it has the usual convention of JavaScript that Object is the name of the constructor function.  Just like Person, Animal, Dog.

So, can the function that is named "Constructor" be named something else?  I don't know the can.js code enough, but is it possible it is called CanObject ?

If so, then if we have

var observable = new can.Observe({});

or

var model = new can.Model();

then we'd nicely have model or observable displayed as a "CanObject", and that follow the usual JavaScript convention.  Or better yet, if it can be that the constructor functions are called  CanBeObserved or CanModel, then it would help even more.



Viewing all articles
Browse latest Browse all 3491

Trending Articles