Dev box
I'm a 32-year-old Ruby on Rails web developer. With the help of friends and co-workers, I've been teaching myself Rails. I worked as a Rails developer for Crowd911 in Colorado. I live in Berlin.
In my developer blog I publish a stochastic array of thoughts and ideas, lessons, mistakes, questions and attempts as answers about Rails and Ruby. I am also posting Anki cards that I used to help myself study. In my view most knowledge is about practice. If you have thoughts, questions, ideas, corrections, arguments, feel free to email me at henryvw@gmail.com.

Javascript in the Browser

When Javascript runs in a Browser, it is always surrounded by a statement like this:

with(window){

[ all your Javascript code ]

}

This window becomes your Global Object - your Browser Object Model, or BOM. 

You can even call special Javascript Browser functions on the window itself:

  • window.open() - open a new window
  • window.close() - close the current window
Read More
Javascript

Javascript variables - what is the difference between var someNumber = 2 and someNumber = 2?

Javascript. What is the difference between:

var someNumber = 2

var someFunction = function() { function doing something }

var someObject = { }

var someObject.someProperty = 5

and

someNumber = 2 ?

someFunction = function() { function doing something }

someObject = { }

someObject.someProperty = 5

 

The answer is that in the Global Scope, there is no difference. You've declared a Global Variable that is accessible everywhere while you're Javascript program is running. But when you define a variable in a Local Scope, the var feature (temporarily) creates a Local Variable that (while your local function is running) overrides the global variable with that name - (if any have been defined). Afterwards, the variable returns to its Global Value.

var someNumber = 2

document.write( someNumber )  ==>  [ 2 ] (global scope)

someFunction() {

    someNumber = 5000

    document.write( someNumber ) ==> [ 5000 ] (local scope)

}

document.write( someNumber ) ==> [ 2 ] (global scope)

 

But, then you might ask, what happens if I define a variable within the local scope of a function, without using "var"?

In that case, WITHOUT the 'var' declaration, you will (permanently) OVER-WRITE the global variable with that name (if any is defined).

var someNumber = 2

document.write( someNumber )  ==>  [ 2 ] (global scope)

someFunction() {

    someNumber = 5000

    document.write( someNumber ) ==> [ 5000 ] (local scope)

}

document.write( someNumber ) ==> [ 5000 ] (global scope)

 

Why does this happen? Because the Javascript var x = something declares a variable in the scope it's in, and the x = something variant is really a property assigner. It's really used more for assigning values to already existing variables. But if the variable doesn't yet exist, then it creates it. 

 

Read More
Javascript, CSS

Having Fun with Scopes Via Javascript

Jonas' Conversation to you. Scopes like candy bars. Calling function a() with function (b) inside. function(a) is in the global scope. function(b) only exists within the "room" of function a().

This is a key difference between Ruby's access variables. The difference has to do with memory. The Ruby variables, perhaps they are restricted to a class or an object. But they all EXIST in memory. Your program is simply restricting access to them based on the rules that you've set.

Javascript functions out of scope do not exist. They are Schroedinger's cat: either dead or alive.

 

Most modern programming languages have a scope level between global(everyone can see it) and local (only this function can see it). JavaScript does not. (In ECMAScript 6 it does have a block-level scope called "let"). Thus, by default, everything that needs to be visible outside of the scope of a top-level function is visible everywhere.

 

Read More
Javascript, Scope

What's A Really Simple and Beautiful Blogging Platform?

Ghost! 

 

https://ghost.org/

 

https://github.com/tryghost/Ghost

Read More
Blog Platform, Blogging, Ghost

What Are 4 Easy Ways to Speed Up My Rails App If It's Maybe Running Slowly?

So glad you asked! There's an excellent blog post that Timo shared with us about this subject from Ruby Weekly.

http://blog.skylight.io/4-easy-ways-to-speed-up-your-rails-app/

Read More
Rails, SQL, Slowness






Footerfull