Essential Books

If you are an application or automation developer in the Ruby space I highly recommend these (selected from several hundred books)

Screenshot from 2017-06-22 07-05-37

Advertisements

HTTP, GET, POST and the REST

Enjoying this once again.

A great way to really understand what’s going on in your browser

If QE’s can aborb most of this (it’s dense – be warned) they’ll be in a good spot with devs!
I suggest a chapter a day (=13 days)

restful_web_apsi

More Javascript for testers

Objects have prototype methods which are shared for all instances

Useful for methods that apply to all instances

Person.prototype.some_method_name=  function() {
  commands;
};

Avoid for properties that store state data, e.g. arrays with elements managed by various methods.

When you need to define multiple methods on the prototype you can use the format below, however they should also define the constructor as shown so that the prototype is Person and not just Object:

Person.prototype = {
  constructor: Person,
  first_method: function() {...},
  second_method: function() {...};  
};

You can add methods to prototypes for all objects including builtins objects such as Array, String, etc.

Inheritance is through above Prototype Chain, e.g.

var instance2 = Object.create(instance1, {
  name: {
    value: "some_new_thing",
    ...
    }
});

next

IIFE – Immediately Invoked Function Expression

Commonly used in javascript for modules.
Note surrounding parens and parens at end

Module Pattern

var person = (function() {
  var age = 25;  // This is private
  return { ... } // These are closures and are public 
}());

Revealing Module Pattern

var person = (function() {
  var age = 25;
  function x() {...}
  return { x: x, ...}; // Note same name (x)
}());

Private Members use ‘this’

  this.getAge = function () { return age; };

 

Javascript Goodies

Functions

function declarations

function thing(p1,p2) {
  code
  return value;
}
  • Starts with word ‘function’
  • Not separately assigned to a variable
  • WILL be hoisted and declared at top

vs

function expressions

var thing = function(p1, p2) {
  code
  return value;
};
  • Assigns function with no name (annoymous) to a named variable
  • Will NOT be hoisted to top, will be defined inline

IIFE’s – immediately invoked function expressions

(function(){ /* code */ }()); // Like this
(function(){ /* code */ })(); // or this
– key identifier is surrounding parens – ()
– invoked at actual runtime

Function Overloading

Achieved with functions by examing arguments, e.g.
function abc() {
   if (arguments.length === 0) {     this code; }   
else {
     other_code;   } }

The three ways to use ‘this’ with methods in javascript functions

1 With call
some_function.call(this, "text")

A particular value for ‘this’ and specific parameters

2. With apply
some_function.apply(this, "text")

A particular value for ‘this’ and, specifically, an array for any parameters

3. With bind
some_function.bind(this, "text")
‘this’ is the value for the new function, the rest are named parameters for ‘new’

Object Properties

Common Internal Properties
  • Extensible
  • Prototype
Data Properties, i.e. values
All Data Properties also have two attribute methods:
  • value
  • writeable
or
Accessor Properties, i.e. functions
All Accessor Properties also have two attribute methods:
  • get
  • set
  e.g.
var tree = {
  _name: "Oak",
  get name() {
    console.log("here1");
    return this._name;
    },
  set name(value) {
    console.log('here2'); 
    this._name = value;
  }
};

Retrieving Property Attributes

Object.getOwnPropertyDescriptor()

Constructors and Prototypes

Constructors use ‘new’ to create a new instance of a method.

Functions should be capitalized when they are used as constructors – you will be creating new instances of them with ‘new’.

All functions have an internal prototype property
You can check for it with object.hasOwnProperty(name)

Rubyists may find its usage has some similarities to Ruby’s class level methods.

When an object (function w/new constructor) has methods that are shared by all instances use a prototype function for the Object

YourObject.prototype.yourFunctionName = function() {...}

When an object (function w/new constructor) has attribute values that are shared by all instances use a prototype attribute for the Object

YourObject.prototype.yourVariableName = value