tnhu / jsface

Small, fast, elegant, powerful, and cross platform JavaScript OOP library. Support main(), singleton, super call, private, mixins, plugins, AOP and more.
MIT License
301 stars 46 forks source link

noConflict does not solve all conflicts #33

Open mcasimir opened 9 years ago

mcasimir commented 9 years ago

Hi buddy, this is not enough:

    oldClass          = context.Class;                                         // save current Class namespace
    context.Class     = Class;                                                 // bind Class and jsface to global scope
    context.jsface    = jsface;
    jsface.noConflict = function() { context.Class = oldClass; };              // no conflict

noConflict "pattern" should allow to preserve global context from pollution completely, you'll need to backup and return jsface too:

    oldClass          = context.Class;                                       // save current Class namespace
    context.Class     = Class;                                                 // bind Class and jsface to global scope
    var oldJsface     = context.jsface;
    context.jsface    = jsface;
    jsface.noConflict = function() { 
       context.Class = oldClass;
       context.jsface = oldJsface;  
       return jsface; 
    };              // no conflict

Now people can use noConflict like this:

var Class = jsface.noConflict().Class;

If you review this comment I can make a PR for you.

mcasimir commented 9 years ago

Actually was too easy to submit a PR: #34

n9986 commented 8 years ago

Is this project dead?

tnhu commented 8 years ago

@mcasimir, I think it's overdone to save and restore jsface. Given development of tooling like webpack and browsersify, commonjs is now supported when you develop javascript for front-end, noConflict becomes less and less useful.