Search This Blog

Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Friday, September 27, 2013

Javscript: the different between apply and call.

apply lets you invoke the function with arguments as an array; callrequires the parameters be listed explicitly.


Pseudo syntax:
theFunction.apply(valueForThis, arrayOfArgs)
theFunction.call(valueForThis, arg1, arg2, ...)
Sample code:
function theFunction(name, profession) {
    alert("My name is " + name + " and I am a " + profession + ".");
}
theFunction("John", "fireman");
theFunction.apply(undefined, ["Susan", "school teacher"]);
theFunction.call(undefined, "Claude", "mathematician");
Source: http://stackoverflow.com/questions/1986896/what-is-the-difference-between-call-and-apply

Thursday, November 8, 2012

Call function in string javascript

1. Using eval
 var strFun1 = "func1";
 var ret1 = eval(strFun1);
 ret1(1,2,3);
 function func1(a,b,c){
   alert(a);
   alert(b);
   alert(c);
}
1. Using Window property (Recommend)
 var strFun2 = "func2";
 window[strFun2](parmas);
 function func2(data){
   console.info(data);
 }


Friday, November 2, 2012

Difference between function and method in javascript

Every function in JavaScript has a number of attached methods, including toString()call(), and apply() (remember that every function in JavaScript is an object).
Functions stand on their own (there is an alert() function, for example), while methods are functions inside an object's dictionary, and we invoke them through the object reference

Example:
function foo()
{
    alert(
'x');
}
alert(foo.toString());


------------------------

fn.call and fn.apply


fn.call(function, [thisObject, [argument1, ..., argumentN]]) is equivalent to function.call(thisObject, argument1, ..., argumentN)
fn.apply(function, [thisObject, [argumentsArray]]) is equivalent to function.apply(thisObject, argumentsArray)

Examples:
function foo(a, b) { return (this*a)-b }
fn.call(foo, 5, 6, 7) == 23
foo.call(5, 6, 7) == 23
fn.apply(foo, 5, [6, 7]) == 23
foo.apply(5, [6, 7]) == 23
  1. if (typeof fn == "undefined" ) var fn = {};
  2. fn.call = function call(fn /*, [thisp, [arg1, ..., argN]]*/) { return Function.prototype.call.apply(fn, Array.prototype.slice.call(arguments).splice(1, arguments.length)) };
  3. fn.apply = function apply(fn, thisp, args) {
  4. if ( args ) args.splice(0, 0, thisp);
  5. return Function.prototype.call.apply(fn, args)
  6. };

Wednesday, November 18, 2009

TIOBE Programming Community Index for November 2009

November Headline: C is closing its gap with Java

The difference between the number 1 and 2 of the TIOBE index is getting smaller. C is only a little over 1% behind Java now. Last time C and Java were so close was in 2005. Both languages show a long-term downtrend, but Java's downtrend appears to be steeper. In two months' time TIOBE will announce the programming language of the year 2009. Candidates so far are: C, C#, PHP and may be even Objective-C.

The TIOBE Programming Community index gives an indication of the popularity of programming languages. The index is updated once a month. The ratings are based on the number of skilled engineers world-wide, courses and third party vendors. The popular search engines Google, MSN, Yahoo!, Wikipedia and YouTube are used to calculate the ratings. Observe that the TIOBE index is not about the best programming language or the language in which most lines of code have been written.

The index can be used to check whether your programming skills are still up to date or to make a strategic decision about what programming language should be adopted when starting to build a new software system. The definition of the TIOBE index can be found here.

Position
Nov 2009
Position
Nov 2008
Delta in PositionProgramming LanguageRatings
Nov 2009
Delta
Nov 2008
Status
1 1 Java 18.373% -1.93% A
2 2 C 17.315% +2.04% A
3 5 PHP 10.176% +1.24% A
4 3 C++ 10.002% -0.36% A
5 4 (Visual) Basic 8.171% -1.10% A
6 7 C# 5.346% +1.32% A
7 6 Python 4.672% -0.47% A
8 9 Perl 3.490% -0.39% A
9 10 JavaScript 2.916% -0.01% A
10 11 Ruby 2.404% -0.47% A
11 8 Delphi 2.127% -1.88% A
12 13 PL/SQL 0.908% -0.03% A
13 38 Objective-C 0.893% +0.74% A-
14 14 SAS 0.816% +0.09% A
15 16 Pascal 0.654% +0.14% A--
16 15 ABAP 0.643% +0.07% A--
17 21 Lisp/Scheme 0.618% +0.15% B
18 22 MATLAB 0.611% +0.15% B
19 20 Lua 0.544% +0.07% B
20 12 D 0.543% -0.90% B

Long term trends

The long term trends for the top 10 programming languages can be found in the line diagram below.


Other programming languages

The complete top 50 of programming languages is listed below. This overview is published unofficially, because it could be the case that we missed a language. If you have the impression there is a programming language lacking, please notify us at tpci@tiobe.com.

PositionProgramming LanguageRatings
21 ActionScript 0.519%
22 COBOL 0.430%
23 Transact-SQL 0.412%
24 FoxPro/xBase 0.379%
25 Fortran 0.376%
26 Logo 0.361%
27 Scratch 0.346%
28 Alice 0.329%
29 Ada 0.305%
30 S-lang 0.292%
31 RPG (OS/400) 0.285%
32 Erlang 0.261%
33 PowerShell 0.259%
34 Scala 0.244%
35 Awk 0.243%
36 Prolog 0.234%
37 NXT-G 0.234%
38 Tcl/Tk 0.221%
39 Focus 0.209%
40 LabWindows/CVI 0.193%
41 Haskell 0.183%
42 PL/I 0.177%
43 JavaFX Script 0.176%
44 MAX/MSP 0.161%
45 LabVIEW 0.157%
46 Falcon 0.156%
47 Groovy 0.152%
48 Modula-3 0.146%
49 Forth 0.144%
50 Smalltalk 0.135%


The Next 50 Programming Languages

The following list of languages denotes #51 to #100. Since the differences are relatively small, the programming languages are only listed (in alphabetical order).

  • 4th Dimension/4D, ABC, AD, Algol, APL, Applescript, Beta, Boo, Bourne shell, C shell, Caml/F#, cg, CL (OS/400), Clean, Clojure, Cobra, cT, Curl, Euphoria, Factor, Fan, Icon, IDL, Inform, Informix-4GL, Io, J, Lingo, MAD, Mathematica, ML, Modula-2, MOO, MUMPS, Natural, Occam, Oz, PowerBuilder, Progress, Q, R, REALbasic, Revolution, SIGNAL, SPSS, SuperCollider, VBScript, Verilog, VHDL, XSLT


November Newsflash - Brought to you by Paul Jansen

  • This month the following changes have been made to the definition of the index:
    • Jean-Michel Biraghi suggested to add the programming language "4D" (formerly known as "4th Dimension") to the index. It enters the chart at position 91.
    • Michael Richter noted that SQL as of SQL-99 is Turing Complete and thus should be counted as a programming language. This is true. But the necessary extension to deserve this predicate, Persisent Stored Modules (SQL/PSM), has never really taken off. So I think it is unfair to call SQL a programming language without renaming it to SQL/PSM. And if we do so, it would not be in the chart because it has for instance only 5 hits for the Google query "SQL/PSM programming".
    • There are still lots of mail that need to be processed. As soon as I have got some time I will answer them. Please be patient.
  • To see the bigger picture, please find the positions of the top 10 programming languages from 4, 10 and 25 years ago in the table below.

    Programming LanguagePosition
    Nov 2009
    Position
    Nov 2005
    Position
    Nov 1999
    Position
    Nov 1984
    Java 1 1 3 -
    C 2 2 1 1
    PHP 3 4 25 -
    C++ 4 3 2 10
    (Visual) Basic 5 5 5 4
    C# 6 7 23 -
    Python 7 8 20 -
    Perl 8 6 4 -
    JavaScript 9 9 17 -
    Ruby 10 24 - -


  • The previous winners of the "Language of the Year" award are shown below.

    YearWinner
    2008 C
    2007 Python
    2006 Ruby
    2005 Java
    2004 PHP
    2003 C++

  • In the tables below some long term trends are listed about categories of languages. The object-oriented paradigm won another 2% to procedural languages in one month's time. The popularity of dynamically typed languages seems to stabilize (see trend diagram below).

    CategoryRatings Nov 2009Delta Nov 2008
    Object-Oriented Languages 54.4% -3.2%
    Procedural Languages 41.6% +2.8%
    Functional Languages 2.8% +0.2%
    Logical Languages 1.3% +0.1%


    CategoryRatings Nov 2009Delta Nov 2008
    Statically Typed Languages 59.2% -0.2%
    Dynamically Typed Languages 40.8% +0.2%

Source: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

Friday, June 19, 2009

Useful scripts and resources Facebook-inspired for web developers

1. FaceBoox Search

FaceBoox is an autosuggest search engine inspired from Facebook for design which uses jQuery as ajax framework and BSN Autosuggest libs.

2. Autobox 2
Autobox 2 is an update of Autobox, a popular jQuery plugin to create input textbox with autosuggest features Facebook-like.

3. TextboxList
TextboxList is a MooTools script similar to Autobox for jQuery. This script turns normal textboxes into a widget which can be navigated with the keyboard, effectively turning your input into a list of items that can be easily deleted. It comes with an Autocomplete plugin.

4. Modal Box
This script is a MooTools clone of Facebook modal box. It’s lightweight, subtle, and very stylish.

5. Facebook Pagination
This script is a Facebook style, unobrusive ajax pagination plug-in for jQuery.

6. Elastic
Elastic is a jQuery plugin which makes your textareas grow and shrink to fit it’s content. It was inspired by the auto growing textareas on Facebook. The major difference between Elastic and it’s competitors is its weight.

7. Facebox
Facebox is a jQuery-based, Facebook-style lightbox which can display images, divs, or entire remote pages. It's simple to use and easy on the eyes. Download the tarball, view the examples, then start enjoying the curves.

8. Tipsy
Tipsy is a jQuery plugin for creating a Facebook-like tooltips effect based on an anchor tag's title attribute.

9. Action Streams
The Action Streams plugin is an amazing new plugin (which imitates Facebook streams on your Wall) for Movable Type 4.1 that lets you aggregate, control, and share your actions around the web as well as a list of your profiles on various services.

10. Facebook Application Icons
This is a collection of 28 free facebook application icons in a high resolution .PNG and .SVG format.

11. mooFacebook
mooFacebook is a port to Mootools of the original Facebox written by Chris Wanstrath with some added features like drag support and titles.

12. Facebook Sliders With Mootools and CSS
David Walsh has created a very simple 3-slider system Facebook-like that allows a user to modify the height, width, and opacity of an image using just sliders.