Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Best practice in extending the built in objects

    I would like to ask people with more knowledge about the framework what's the best way to go about doing the following (using the JS client only).

    I would like to extend the built in objects (such as buttons, windows, etc) so I can add some rights management properties. For example, I would like to add a property "groupNames" to explicitly list the names of the access groups who can see that object.

    I know how to do this by deriving another object from the built in objects, that is quite simple to achieve. What I wonder is is it's possible to extend the built in objects without deriving new objects (so we don't end up with our own naming for half of the framework just for adding a property and some logic).

    Is this achievable, or not recommended? If achievable, how would one go about doing it?

    What I tried to do is use addProperties to overwrite the initWidget function, perform my validation, and then call this.Super. As expected, this ended up messing up things, as (to my understanding) it is just overwriting the normal implementation of the method.

    Thanks,
    Sorin

    #2
    Hi,

    I'd be curious to hear Isomorphic's official response to this question. Whenever I had to do this, I had to tweak around
    with the prototypes and I'd really like to clean up that code and make it more by-the-book ...

    Any insight from Isomorphic ?

    Thanks,

    Comment


      #3
      Typically, this is how I've done it so far, but again, I'm not convinced it's right way of "spoofing" existing
      classes without actually having to create extended versions of such classes ...

      Code:
      // grab copy of the original handleClick() method
      
      isc.SelectItem.addMethods
      ({
          handleClickOriginal : isc.SelectItem.getPrototype().handleClick
      });
      
      // add new implementation for handleClick() method which calls original one
      
      isc.SelectItem.addProperties
      ({
         //--------------------------------------------------------------------
         handleClick : function ()
         {
            if (this.isReadOnly())
               return false;
      
            return this.handleClickOriginal(arguments);
         }
      });
      If at all possible, thanks for providing "the official way" of doing such code injection, without fully sub-classing per say.

      Thanks,

      Comment


        #4
        Subclassing is really the only recommend and supported way to do this, but for those that are comfortable hacking outside of those boundaries (and troubleshooting any such problems that arise, and eliminating any such customizations as a possible cause before seeking support..) what yavery showed is the right approach. It's what we often do for patches as well.

        Comment


          #5
          Thanks for your feedback.

          Comment


            #6
            Thanks for the solution and feedback

            Comment

            Working...
            X