Home > JavaScript > JavaScript – References

JavaScript – References

# + with some care

$x = “123” ; $x ++ ;  print $x  ; // output is 124
but
x = “123” ; x = x + 1;  print x; //output is 1231
so. !

# class/objects

o = {

a:7,

get b() { return this.a+1; },

set c(x) { this.a = x/2; }

};

var _myClass = ( function () {

_a = function() { return ‘hello’; }     _b = function() { return ‘ world’; }

return {

_myarr= [ a , b, c], _suba = _a(), _subb = _b(),

_main = function ( param) {  this._myarr.a }

}


(function($) {

var opt;

$.fn.myplug = function ( param1) {

opt  = $.extend ( { }, param1 , $.fn.more );

}

$.fn.more = { one :  ‘me’, two: ‘you’  };

})(jQuery);

})(); //End of _myClass


function MyObject(name, message) {
this.name = String(name);
this.message = String(message);
}
MyObject.prototype = {
getName: function() {
return this.name;
},
getMessage: function() {
return this.message;
}
};

// InstanceOF maintain….
<div id=ok></div>  <div id=bk></div>
<script>
// InstanceOf example:
(function($){
var opt=null;
// private
$.fn.one = function(param) {
opt = $.extend( {} , param, $.fn.one.default );
opt.one = $(this).attr(‘id’);
return opt;
}
// Outside to Insdie allow
$.fn.one.default = {
one: 1,      two: function(){ $ ( ‘#’ + this.one ).html(  this.one   ) ;  }
};

})(jQuery);

var abc = $(‘#ok’).one(); abc.two();
var abc = $(‘#bk’).one(); abc.two();

</script>


# operators

 

?
status = (you >= 10) ? "ok" : "minor"

 

delete
delete objectName

 

 

 

in
// Arrays
trees=new Array("redwood","bay","cedar","oak","maple")
0 in trees        // returns true
3 in trees        // returns true
6 in trees        // returns false
"bay" in trees    // returns false (you must specify the index number,
                  // not the value at that index)
"length" in trees // returns true (length is an Array property)

// Predefined objects
"PI" in Math          // returns true
myString=new String("coral")
"length" in myString  // returns true

// Custom objects
mycar = {make:"Honda",model:"Accord",year:1998}
"make" in mycar  // returns true
"model" in mycar // returns true

 

instanceof
theDay=new Date(1995, 12, 17)
if (theDay instanceof Date) {
   // statements to execute
}

typeof CLASS/Objects

void ( expression ) The void operator specifies an expression to be evaluated without returning a value.

# Live connect

var myString = new java.lang.String(“Let me smell it”); print  (myString);

Firefox we can connect to java, but IE , Chrome etc is not allowing that,

in that case we can have jApplets.

My references: http://www.crockford.com/


Advertisements
Categories: JavaScript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: