Blogs

Object-Oriented JavaScript: Classy Properties...

If you've been following along on these object-oriented JavaScript posts, then you should already know quite a bit about JavaScript classes and objects. But wait – there's more!

Today I'm going to talk about class properties. As the name implies, these are properties associated with a class, as opposed to an instance. You already know about one of these: the special class property called prototype. But you can also use class properties for other things, including both values and functions (methods).

The classic use for a class property is for a getter method: a class method that returns an instance. And a classic use for a value class property is to hold a collection of instances. Here's an example of both:

Geek Humor Break...

Q. Why do computer geeks get Halloween confused with Christmas?

Object-Oriented JavaScript: Properties, Variously...

In our earlier examples (see links below the fold) we had two examples of instance properties: birth_date and call_name. To review, these are properties that exist in each instance of a class. For example, if I have two Dog instances (one for Miki and one for Lea), each of them will have its own birth_date and call_name, with independent values (that could be either the same or different from each other).

But what if you want a property that's the same for all instances of a class? Is there a way to do that?

You betcha!

Object-Oriented JavaScript: Literally, He Says...

Yesterday I showed you how to add a method to the Dog class (see navigator links below the fold). Today I'm going to add a second method, but more importantly, I'm going to show you how to define class methods in a slightly more convenient way, using a feature of JavaScript called an object literal, also called JavaScript Object Notation (or JSON for short, pronounced JAY-sahn).

Just to be clear, before I introduce the JSON way, you could add the new class method using the same way I showed you yesterday. The JSON way is just a bit easier, with a little less cluttered code. When you start delving into the OO JavaScript that comes with our product, you'll see that we've used the JSON approach almost exclusively, just by convention.

So what is this JSON stuff? Glad you asked:

Object-Oriented JavaScript: A Methodical Step...

Yesterday I showed you how to make a very simple JavaScript class, and promised you that next I'd show you how to build the code that calculates a dog's age right into it. Well, that day has arrived, as the famous lass (do you know who she is?) at right is anticipating.

We're going to accomplished this OO miracle by adding an age method to the Dog class. What's a method, you ask? Well, I'm here to answer:

Object-Oriented JavaScript: First Steps...

This post is the first in a series, intended to be an introduction into writing object-oriented programs in JavaScript. All of the examples will be done in the Service-now.com server-side environment, but the subjects covered are just as applicable to writing client-side (in the browser) JavaScript – the only differences are details about where the code goes and the collection of browser-specific classes and functions that have no equivalent on the Service-now.com instance (server-side).

The cute little fellow at right is Miki, our youngest field spaniel, when he was just ten weeks old. That was back in 2006; he's now all grown up and competing in canine agility trials. He's still cute, and he still likes sticks. He's also (unbeknownst to him) the star of today's post: we're going to make a Dog class, and he's going to be the first object of that class.

Did I just descend into gobbledegook?

Tips and Tricks: Yes, Really - Anywhere At All...

Yesterday I told you about on-demand functions – and right away I get some emails. Some of you said “Enough with the esoteric, high-falutin' math nonsense – give us something practical!”, and the rest said “Surely this doesn't work with reference qualifiers?”

Well, I thought it was pretty clear when I said that on-demand functions work in any script, anywhere, anytime. Apparently not! So here's a practical (if a little unlikely) example: a reference qualifier using an on-demand function. On my instance, I'm going to modify the “Configuration item” field on the incident form so that it only shows computers:

SNC Reporting User Guide

Downloaded the "Pre-Made Book" called Reporting Data off the Wiki. Great content! Perfect way to equip those curious with how to work with Reports in SNC. Also found a few plugins that we don't have turned on that will take reporting from good to FANTASTIC! Didn't know I could download data from other sources to create a custom report - have been telling everyone it's not possible, which it's not without the Custom Charts plugin. Minnesota Local User Group has been asking for assistance with reporting - and the instructions have been right under our noses all this time. Thanks, SNC!!!

New Feature: On-Demand Functions...

She seems a bit skeptical about this, but it's true – starting with the Fall 2010 release, you'll be able to define functions whose definitions are automatically included when you use them.

This is much different than a feature you may already be familiar with: global business rules. All global business rules are loaded (included) before you run any script. The more global business rules you define, the less efficient this process is.

On-demand functions, on the other hand, are only loaded (included) when you actually use them in a script. That means you can define as many of them as you'd like without any loss of efficiency.

So how does this work?

Pretty Links and Perma Links

This morning I sent our CEO a link that kind of looked like this:

https://DEMO.service-now.com/sys_attachment.do?sys_id=8fcb35c60a0a3c1c017cd77b61309ec8&sysparm_viewer_table=kb_knowledge&sysparm_viewer_id=8fc8c91f0a0a3c1c0149bc22d14c4848

I was pretty embarrassed. I then realized I could use just the Sys_ID, and that's good, but not good enough for me.

Syndicate content