JavaScript Archives - Ryan Kienstra

Write jQuery Plugins

How To Write jQuery Plugins

By: Ryan Kienstra on: February 7, 2015  in: JavaScript

You’ve written complex jQuery code. And you’d like it to be clearer, or more flexible. Maybe you’ve heard how easy it is to extend jQuery. Here’s why and how to write jQuery plugins. Why Write jQuery Plugins? 1. Use 1 less argument jQuery plugins could be plain functions. But they’d have to take a jQuery […] Read more

Prevent JavaScript Bugs icon

7 Ways To Prevent JavaScript Bugs

By: Ryan Kienstra on: January 27, 2015  in: JavaScript

JavaScript is flexible, and it doesn’t throw many errors. But it makes it easy to create bugs. These 7 conventions will¬†help you prevent JavaScript bugs. 1. Equality Operators Use === and !== not == and != The expression ( foo === "" ) is more reliable than ( foo == "" ). The operator === […] Read more

JavaScript modules

JavaScript Modules In WordPress

By: Ryan Kienstra on: January 25, 2015  in: JavaScript

Most JavaScript files in WordPress¬†are actually modules. This makes all of the variables and functions private. And lets you control what should be public. JavaScript modules are: More secure Easier to change Creating A Module Wrap the entire file in a function. ( function( $ ) { // file contents } )( jQuery ); This […] Read more

JavaScript variable declaration

JavaScript Variable Declaration

By: Ryan Kienstra on: January 24, 2015  in: JavaScript

Good PHP developers can learn basic JavaScript quickly. But JavaScript variable declaration is different from PHP. And forgetting declarations will cause subtle bugs, not errors. Variable Declaration Declare all variables by using var var myVariable = 'foo_string'; If you don’t, you’ll make the variable global. var scopeTest = function() { accidentalGlobal = 'The value inside […] Read more