Showing posts with label Java Script. Show all posts
Showing posts with label Java Script. Show all posts

Friday, August 17, 2012

JAVA SCRIPT: arguments variable

arguments

this is a key word var in javascript it holds all vars past to a function regardless if the constructor could assign them or not. So in short this allows you to create functions with an arbitrary number of functions.

JAVASCRIPT:JS-LINT

Today I learned about JSLINT. Js Lint is a program to which you can run your javascript through to check for errors, coding style and various conventions. As javascript has very loose rules it difficult to debug. Following the JSLINT conventions and rules will hopefully help you produce better, more reusable and sharable code. JSLINT was a developed by Yahoo's top developers.

you can get JSLINT and documentation at:
http://www.jslint.com/

also see the videos by Douglas Crockford at
http://www.youtube.com/results?search_query=Douglas+Crockford&oq=Douglas+Crockford&gs_l=youtube.3..35i39j0l9.5610.7677.0.8340.5.5.0.0.0.0.208.775.0j4j1.5.0...0.0...1ac.RCxFWzyRivM

Douglas Crockford: The JavaScript Programming Language

Why learn JavaScript & some great video footage

Watch these videos (sorry have to use youtube) since the normal hosting site is a joke!

I have update this link, will make it easier to locate all 3 movies!
http://www.youtube.com/playlist?list=PL5586336C26BDB324&feature=plcp

I'm always reading about creating fast and usable websites

Ever wounder why people refuse to use  or abandon websites: I have started a list of examples of such sites.

1.) http://www.yuiblog.com/blog/2010/02/03/video-crockonjs-1/ # just try to down load the HD videos have fun, or you an opt for the alternative and watch the embedded one which will give you a total headache in minuets because of the poor sound and video quality.

Thursday, August 16, 2012

javaScript: Nested Functions

Another Intresting concept that poped up in JavaScript
:nested functions inside of other functions : This provides a way to make a function private. If you want these be accessable there must be a accessor method in the outfunction otherwise they will be unreachable outside of the outter function

Here is an Example of what this looks like.

<!DOCTYPE html>
<html>
<head>
    <title>Nested Functions</title>
    <script type="text/javascript">
          function initiateMadness() {
            var sparta = {
                name : "Sparta"
            };
            function madness() {
                alert("THIS. IS. " + this.name.toUpperCase() + ".");
            }
            document.onclick = makeAMessenger(madness, sparta);
        }
       
//access the content of the inner function
   function makeAMessenger(func, context)
        {  
            window.name = context.name;
            func();
        }
        initiateMadness();
    </script>
</head>
<body>
<script type="text/javascript">
</script>
<h1> Heading 1 </h1>
<p> THis is my program </p>
    
</body>
</html>

Java Script : Array of functions

Another intersting concept that I came across:
Java Script allows you to create an array of functions, took me a while to make this work but I finally got it. Here is example of how to do this:

<!DOCTYPE html>
<html>
<head>
    <title>Array of functions</title>
<script type="text/javascript">
  
function transform(array)
   {
         function makeFunction(value)
             {return function()
                {
                    return value;
                }
             }
         
       var output = new Array();
       for(var i = 0; i < array.length; ++i)
          {
              output[i] = makeFunction(array[i]);
          }
       return output;
   }
</script>
</head>
<body>
<script type="text/javascript">
myArray = [1,2,3,4,5];
myArray = transform(myArray);
for(var i =0 ; i < myArray.length; ++i)
{
    alert( myArray[i]());
}
</script>

</body>
</html>

Tuesday, August 14, 2012

Java Script Notes + html

!
      <!--   script goes here  //--> #this format will hide the script from the user


A
  
action   =[url] #Specifies where to send the form-data when a form is submitted 

B
  boxes # pops up a box for the user to interact with
     types
          alert #alert("sometext");  use to alter user they missed something
          confirm#comfirm("some text"); use to confirm something
          prompt#prompt("some text",defaultValue)
                example# var userName=prompt("Please enter your name","Harry Potter");


  Break in line #<br /> #add a line break


 button # creates a button user can interact with
   Sub Types
         #button
             #<button type="button" onclick="myFunction()">



button methods # used to program the button
   #onclick
       #<button type="button" onclick="myFunction()">

D
  
   document  #javascript class with many function
       functions
                  .getElementById   #access html element
                         #document.getElementById("demo").innerHTML="My First JavaScript";
                   .write # write directly into the html document
                         #document.write("<p>My First JavaScript</p>");



F

<form> Creates a form for the user to enter data

 function <function name> #design your own java Script function f
     #function myFunction(){code goes here}



I

id " " id html element
    #<p id="demo">My First Paragraph</p>

input type = "type goes here "#create a moduel the user can interact with
  #button

R
   return #used to return a value at end of a function



S
 scr = "scriptname.js" # points and loads external java script file
 <script> Insert Java Script

 <script type =" script type">
     #text/javascript


U
<ul> #unordered list
    #followed by several <li> # list item
V

value # assign a value to a button (value is usally a string of text)
  

var  [var name] # declare a variable