views:

48

answers:

2

This is a basic question. Sorry.

I have the following code:

$extend(ImageCrop, Options.prototype);
Swiff.Uploader = new Class({
    Extends: Swiff,
    Implements: Events,
    options: {
        path: "Swiff.Uploader.swf",
        target: null,
        zIndex: 9999,
        height: 30,
        width: 100,
        callBacks: null,
        params: {
            wMode: "opaque",
            menu: "false",
            allowScriptAccess: "always"
        },
        typeFilter: null,
        multiple: true,
        queued: true,
        verbose: false,
        url: null,
        method: null,
        data: null,
        mergeData: true,
        fieldName: null,
        fileSizeMin: 1,
        fileSizeMax: null,
        allowDuplicates: false,
        buttonImage: null,
        policyFile: null,
        fileListMax: 0,
        fileListSizeMax: 0,
        instantStart: false,
        appendCookieData: false,
        fileClass: null
    },
    initialize: function (b) {
        this.addEvent("load", this.initializeSwiff, true).addEvent("select", this.processFiles, true).addEvent("complete", this.update, true).addEvent("fileRemove", function (e) {
            this.fileList.erase(e)
        } .bind(this), true);
        this.setOptions(b);
        if (this.options.callBacks) {
            Hash.each(this.options.callBacks, function (f, e) {
                this.addEvent(e, f)
            }, this)
        }
        this.options.callBacks = {
            fireCallback: this.fireCallback.bind(this)
        };
        var d = this.options.path;
        if (!d.contains("?")) {
            d += "?noCache=" + $time()
        }
...............................

When i set breakpoint on this.setOptions(b); and look value of b varible i see already initialized varible but why? Where i set value of b? I just pass it as parametr. I think value of b must be 'null' or something.

+1  A: 

when you use the Options class as a mixin, all it does is a $merge() of this.options with arguments passed on the this.setOptions(). the initialize serves as the constructor and normal practice in mootools is to have an options object passed on to it.

here's an example class:

var foo = new Class({
    Implements: [Options],
    // set defaults.
    options: {
        foo: "bar",
        log: true        
    },
    initialize: function(options) {
        this.report(); // "bar"
        this.setOptions(options); // merge argument options with this.options
        this.report(); // whatever the value of options.foo was
    },
    report: function() {
        if (this.options.log)
            console.log(this.options.foo);
    }

}); 

// this will output bar and then test.
new foo({foo:"test"}).report();

it allows you to populate your class instance with settings/data as defaults that the instantiation can override. for example, you can also pass new foo({log: false}); which will suppress all output.

Dimitar Christoff
A: 

If you set a breakpoint within that method it will not be hit until you run the method, i.e not when the definition is parsed but when you create an object. At that point you are probably passing an argument if b is set. So, to say it again in other words: when you define your uploader, the breakpoint is not hit. It is hit later when you create an instance.

ormuriauga