[ダイアログを出す]
alert( "Debug Message" );
[コンソールに出力]
console.log( "Debug Message" ); console.error( "Error Message" ); console.warn( "Warning Message" );
ダイアログをいちいち消す必要がないのでコンソールに出した方がラクチン
alert( "Debug Message" );
console.log( "Debug Message" ); console.error( "Error Message" ); console.warn( "Warning Message" );
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <title>JavaScriptTest</title> <script type="text/javascript"> JavaScriptコード </script>
var a = [ 0, 1, 2 ]; alert( a.length ); // 3 a[ 3 ] = 3; alert( a.length ); // 4
var a = 3; var b = a; alert( "a = " + a ); // a = 3 alert( "b = " + b ); // b = 3 a = 5; alert( "a = " + a ); // a = 5 alert( "b = " + b ); // b = 3
var a = new Object(); a.property = 10; var b = new Object(); b = a; alert( "a.property = " + a.property ); // a.property = 10 alert( "b.property = " + b.property ); // b.property = 10 a.property = 5; alert( "a.property = " + a.property ); // a.property = 5 alert( "b.property = " + b.property ); // b.property = 5 !!! b.property = 8; alert( "a.property = " + a.property ); // a.property = 8 !!! alert( "b.property = " + b.property ); // b.property = 8
var a = { property : 10 };
var b = a;
alert( "a.property = " + a.property ); // a.property = 10
alert( "b.property = " + b.property ); // b.property = 10
a.property = 5;
alert( "a.property = " + a.property ); // a.property = 5
alert( "b.property = " + b.property ); // b.property = 5 !!!
b.property = 8;
alert( "a.property = " + a.property ); // a.property = 8 !!!
alert( "b.property = " + b.property ); // b.property = 8
var a = new Object(); a.property1 = 1; // オブジェクト名.プロパティ名 = 値 a.property2 = 2;
var a = {
property1 : 1, // プロパティ名 : 値
property2 : 2,
};
var car = function(){};
car.prototype = {
run:function(){
alert( "走る" );
}
};
var truck = function(){};
truck.prototype = new car();
truck.prototype.carry = function(){
alert( "運ぶ" );
};
var truck1 = new truck();
truck1.run();
truck1.carry();
var car = function(){};
var car = function( _maker, _color ){
this.maker = _maker;
this.color = _color;
};
var car = function( _maker, _color ){
this.maker = _maker;
this.color = _color;
};
car.prototype = {
getColor : function(){
alert( "この車の色は" + this.color + "です。" );
}
}
var car = function( _maker, _color ){
this.maker = _maker;
this.color = _color;
};
car.prototype = {
getColor : function(){
alert( "この車の色は" + this.color + "です。" );
}
}
var myCar = new car( "toyota", "white" );
myCar.getColor();