Question

I'm trying to run an A/B test for a new feature I'm adding to a website. In the past, our team has done something like this before showing various features on the page:

someUserActionThatEnablesFeature:function(){
    experiments.isUserInControlGroup('new-feature1') && newFeature1Obj.show();
}

someUserActionThatDisablesFeature:function(){
    experiments.isUserInControlGroup('new-feature1') && newFeature1Obj.hide();
}

I have found this to be pretty kludgey, since we have to check if the experiment is enabled in every place we use the new feature. What I was thinking about doing instead something like this:

function NewFeature1(){
    //constructor
}

NewFeature1.prototype = {
    show:function(){
        //do something
    },
    hide:function(){
        //do something
    },
    //etc
};

//before any objects are declared
if (experiments.isUserInControlGroup('new-feature1')) {
    for(var prop in NewFeature1.prototype) {
        //replace with empty function
        NewFeature1.prototype[prop] = function(){};
    }
}

The idea here is that I'm replacing the NewFeature1 class's methods with empty stubs before I ever instantiate it, thereby ensuring that none of my calls on the object will ever do anything if the user isn't in the control group.

Is this dangerous in some browsers? I couldn't tell in my initial tests if I was overwriting Object's properties. In webkit, it didn't seem like it was hurting anything. Am I missing something? I only have to worry about webkit, FF, and IE8+. Thanks!

Pas de solution correcte

Autres conseils

I think it's acceptable, maybe better to stub only direct properties determined by hasOwnProperty if the class has no inherits.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top