Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Matthew Stokeley matthewstokeley

🎯
Focusing
Block or report user

Report or block matthewstokeley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View verbosely-named-functions.js
const nameOfTheFunction = function nameOfTheFunction() {
// ...
}
// trace sanity
View conditional-query-parameter-key.php
<?php
// graceful degradation
if ( ! isset( $_GET )
|| empty( $_GET )
|| ! isset( $_GET[ KEY ] ) ) {
exit();
@matthewstokeley
matthewstokeley / jquery-class-method.js
Last active Aug 14, 2019
maintaining backwards compatibility
View jquery-class-method.js
/**
* @version 0.0.1
*/
class GenericUIComponent
{
constructor( options ) {
this.className = options.className
}
View find-method.php
<?php
// an example of what the word 'robust' means in the context of api's.
function _find( $needle, $haystack, $is_key = false ) {
if ( $is_key === true ) :
return function( Callable $comparator ) use ( $needle ) {
return call_user_func( $comparator, $needle );
}
View str_repeat.php
<?php
// ...
str_repeat( self::tab, ( ( int ) $depth ) ) . str_repeat( self::tab, $nesting_level );
@matthewstokeley
matthewstokeley / gist:dea3f7cc56da3f40dd80da19ab4ffe6f
Last active Aug 16, 2019
underscore-style prototype cloning
View gist:dea3f7cc56da3f40dd80da19ab4ffe6f

Underscore-style prototype chaining

Cloning the prototype allows the user to conform to the convention of not mutating an object's prototype while extending the flexibility of the prototypal chain.

@matthewstokeley
matthewstokeley / monorepo.md
Created Aug 4, 2019
mono repo ongoing links
View monorepo.md
View annotated-iife-scope.md

Lexical scope

Javascript does not have a mechanism to preserve the global namespace, which can lead to namespace collisions and other errors. Foundation uses a one-line initialization script, var foundation = {}, to create an object that can function as a namespace. In Javascript, when an object is declared, an environment record or scope is also created - functions and variables located within the same environment record have access to each other. Objects and functions contain their own environment record. try catch blocks and conditionals do not.

The IIFE was a popular construct used in the development of jQuery and documented in Addy Osmani's JS Design Patterns as the revealing module pattern to help avoid namespace and scope collisions by wrapping a function with an immediately-invoked function - the wrapper is invoked on runtime and functions and variables are declared within the IIFE's scope rather than what is referred to as the global scope.

View _el-add-class.js
/**
* This method is several years old and is being produced here to continue the discussion
* about what is considered production-level element attribute toggling.
*
* Both jQuery and twbs are widely used in production sites and can be used
* as standards for production-level acceptance criteria.
*
* jQuery is similar to this method - it looks for
* classList first and then falls back to className.
*
View navigation-traversal-methods.js
const _containsActiveClass = function( _el, i ) {
for ( ; i < _el.children.length; i++ ) {
if ( _el.children[ i ].children[ 0 ] ) {
return _containsActiveClass( _el.children[ i ], 0 )
}
return _el.children[ i ].classList.contains( ACTIVE_CLASS )
You can’t perform that action at this time.