JavaScriptオブジェクトは、コンテナの属性変数であります
1.内部オブジェクト
標準の椎オブジェクト
typeof 123
"number"
typeof '123'
"string"
typeof true
"boolean"
typeof NaN
"number"
typeof []
"object"
typeof {}
"object"
typeof Math.abs
"function"
typeof undefined
"undefined"
1.Date
基本的な使用
var now = new Date(); //Sat Jan 04 2020 10:47:06 GMT+0800 (中国标准时间)
now.getFullYear(); //年
now.getMonth(); // 月 0~11 代表月
now.getDate(); // 日
now.getDay(); // 星期几
now.getHours(); // 时
now.getMinutes(); // 分
now.getSeconds(); // 秒
now.getTime(); // 时间戳 全世界统一 1970 1.1 0:00:00 毫秒数
console.log(new Date(1578106175991)) //时间戳转为时间
変更
now = new Date(1578647754614)
Fri Jan 10 2020 17:16:29 GMT+0800 (中国标准时间)
now.toLocaleString // 注意,调用是一个方式,不是一个属性!
ƒ toLocaleString() { [native code] }
now.toLocaleString()
"2020/1/10 下午17:16:29"
now.toGMTString()
"Fri Jan 10 2020 17:16:29 GMT+0800 "
2.JSON
JSONとは何ですか
早い段階で、すべてのデータの伝送は、XMLファイルを使用してに慣れています!
- JSON(JavaScriptのオブジェクト表記、JS表記オブジェクト)は、軽量データ交換フォーマットです。
- シンプルで明確な階層メイクJSON理想的なデータ交換言語。
- 簡単に解析し、生成し、かつ効果的にネットワーク伝送の効率を改善するために、マシンにも簡単に読み取りおよび書き込み、これだけに。
JavaScriptではすべてがサポートJSのいずれかのタイプを表すためにJSONを使用することができ、オブジェクトであり、数、文字列...
フォーマット:
- {}を持つオブジェクト
- アレイが使用されています[]
- 値:すべてのキーと値のペアは、キーを使用しています
変換JSON文字列オブジェクトとJS
var user = {
name: "yy",
age: 18,
sex: '女'
}
//对象转化为json字符串 {"name":"yy","age":18,"sex":"女"}
var jsonUser = JSON.stringify(user);
//json 字符串转化为对象 参数为 json 字符串
var obj = JSON.parse('{"name":"yy","age":18,"sex":"女"}');
多くの人々は違い、JSONやJSのオブジェクトを知りません
var obj = {a: 'hello',b:'hellob'};
var json = '{"a": "hello","b":"hellob"}'
3.Ajax
- JSネイティブ非同期要求書かXHR
- メソッドjQueyパッケージ$( "#名")。アヤックス( "")
- リクエストaxios
2.オブジェクト指向プログラミング
プロトタイプオブジェクト
ジャバスクリプトやJava、C#の。。。。オブジェクト指向; javascriptのいくつかの違い!
- クラス:テンプレートプロトタイプオブジェクト
- オブジェクト:具体例
JavaScriptでは、この必要性は、思考の私の方法を変更するには!
プロトタイプ:
var Student = {
name: "yy",
age: 18,
run: function () {
console.log(this.name + " run....");
}
};
var xiaoming = {
name: "xiaoming"
};
//原型对象
xiaoming.__proto__ = Student;
var Bird = {
fly: function () {
console.log(this.name + " fly....");
}
};
// 小明的原型 是 Student
xiaoming.__proto__ = Bird;
function Student(name) {
this.name = name;
}
// 给student新增一个方法
Student.prototype.hello = function () {
alert('Hello')
};
クラスの継承
class
ES6で導入されたキーワード、
1、クラス、プロパティ、メソッドの定義
// 定义一个学生的类
class Student{
constructor(name){
this.name = name;
}
hello(){
alert('hello')
}
}
var xiaoming = new Student("xiaoming");
var xiaohong = new Student("xiaohong");
xiaoming.hello()
2、継承
<script>
//ES6 之后=============
// 定义一个学生的类
class Student{
constructor(name){
this.name = name;
}
hello(){
alert('hello')
}
}
class XiaoStudent extends Student{
constructor(name,grade){
super(name);
this.grade = grade;
}
myGrade(){
alert('我是一名小学生')
}
}
var xiaoming = new Student("xiaoming");
var xiaohong = new XiaoStudent("xiaohong",1);
</script>
自然:Viewオブジェクトのプロトタイプ
__ __プロト: