[wp-trac] [WordPress Trac] #33657: wp.customize.Container.onChangeActive uses "construct" variable name instead of "container"

WordPress Trac noreply at wordpress.org
Wed Sep 2 20:37:57 UTC 2015


#33657: wp.customize.Container.onChangeActive uses "construct" variable name
instead of "container"
-------------------------+------------------------------
 Reporter:  ericlewis    |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Customize    |     Version:  4.3
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:  javascript
-------------------------+------------------------------

Comment (by ericlewis):

 Alternatively, we could use `this` for using execution context, and
 consider adding that to the [https://make.wordpress.org/core/handbook
 /best-practices/coding-standards/javascript/ JavaScript coding standards].

 I know there's a pattern of using the name of the class as execution
 context in Customizer JS (e.g. `container` for `api.Container`), so
 there's a preference here I don't want to dismiss outright.

 However, I'll make the case for `this`. `this` is a native construct to
 the language, so you can open up a random object or class method and
 understand what `this` is with no pretext or research.

 Using `this` would avoid awkward duplication in the case of this ticket:

 {{{
 #!javascript
 // this line is awkward
 focusContainer = container.container.find( 'ul:first' );
 // this line reads more clearly
 focusContainer = this.container.find( 'ul:first' );
 }}}

 For sharing execution context across scopes (e.g. inside a nested callback
 function), I don't have a particular preference. `var self = this` is
 common, but as this is not a native part of the language, everything is
 convention.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33657#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list