Tutorial by Examples

let sel = document.getSelection(); sel.removeAllRanges();
let sel = document.getSelection(); let myNode = document.getElementById('element-to-select'); let range = document.createRange(); range.selectNodeContents(myNode); sel.addRange(range); It may be necessary to first remove all the ranges of the previous selection, as most browsers don't s...
let sel = document.getSelection(); let text = sel.toString(); console.log(text); // logs what the user selected Alternatively, since the toString member function is called automatically by some functions when converting the object to a string, you don't always have to call it yourself. console...
To create a custom template we first need to create php file in a theme directory. You can name it almost any way you want. For this example we will create example.php One and only thing we need to define inside our example.php, to be recognized by WordPress as a template, is template name. We do t...
Let's extend our template from above and include content from header.php and footer.php Including header: We will include header right after Template name comment There are two common ways to do this. Both are right and work same, it's just about your style and how code looks First way: <?ph...
We will further extend our template and include title of the page and a content <?php /* Template Name: Example */ get_header(); the_title(); the_content(); get_footer(); And if you want you can wrap them with HTML elements like this <?php /* Template Name: Example *...
If we have a struct like this struct Box { let name: String let thingsInside: Int } and an array of Box(es) let boxes = [ Box(name: "Box 0", thingsInside: 1), Box(name: "Box 1", thingsInside: 2), Box(name: "Box 2", thingsInside: 3), B...
Some attributes are directly accessible as properties of the element (e.g. alt, href, id, title and value). var a = document.querySelector("a"), url = a.href; Other attributes, including data-attributes can be accessed as follows: var a = document.querySelector("a"), ...
Download Heroku Toolbelt. Navigate to the root of the sources of your Django app. You'll need tk Type heroku create [app_name]. If you don't give an app name, Heroku will randomly generate one for you. Your app URL will be http://[app name].herokuapp.com Make a text file with the ...
Values can be given names using let: # let a = 1;; val a : int = 1 You can use similar syntax to define a function. Just provide additional parameters for the arguments. # let add arg1 arg2 = arg1 + arg2;; val add : int -> int -> int = <fun> We can call it like this: # add 1...
The function keyword automatically has pattern matching when you define the body of your function. Observe it below: # let foo = function 0 -> "zero" | 1 -> "one" | 2 -> "couple" | 3 -> "few" | _ -> "many";; val foo : int -&gt...
Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the member elements of a collection, list, or sequence. Example struct DaysOfWeek { var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri"...
3.0 let string = "My fantastic string" var index = string.startIndex while index != string.endIndex { print(string[index]) index = index.successor() } Note: endIndex is after the end of the string (i.e. string[string.endIndex] is an error, but string[string.startIndex] i...
A defer statement in Go is simply a function call marked to be executed at a later time. Defer statement is an ordinary function call prefixed by the keyword defer. defer someFunction() A deferred function is executed once the function that contains the defer statement returns. Actual call to th...
[1, 2, [[3, 4], [5]], 6].flatten # => [1, 2, 3, 4, 5, 6] If you have a multi-dimensional array and you need to make it a simple (i.e. one-dimensional) array, you can use the #flatten method.
In case you need to read an array elements avoiding repetitions you case use the #uniq method: a = [1, 1, 2, 3, 4, 4, 5] a.uniq #=> [1, 2, 3, 4, 5] Instead, if you want to remove all duplicated elements from an array, you may use #uniq! method: a = [1, 1, 2, 3, 4, 4, 5] a.uniq! #=> [1...
Standard enumerations allow users to declare a useful name for a set of integers. The names are collectively referred to as enumerators. An enumeration and its associated enumerators are defined as follows: enum myEnum { enumName1, enumName2, }; An enumeration is a type, one which is...
A common use for enumerators is for switch statements and so they commonly appear in state machines. In fact a useful feature of switch statements with enumerations is that if no default statement is included for the switch, and not all values of the enum have been utilized, the compiler will issue ...
If targeting Flash Player 11+, the built-in removeChildren method is the best way to remove all children: removeChildren(); //a start and end index can be passed For legacy applications, the same can be accomplished with a loop: while (numChildren > 0) { removeChildAt(0); }
Enums in Swift are much more powerful than some of their counterparts in other languages, such as C. They share many features with classes and structs, such as defining initialisers, computed properties, instance methods, protocol conformances and extensions. protocol ChangesDirection { mutati...

Page 359 of 1336