物件裡面可以包含很多Type 的屬性,本篇主要陳述每個取值、新增、刪除的方式
取值、新增、刪除的方式可以利用物件. 標記號(點的方式) 呼叫出來!
https://chiangyuchi.github.io/2019/05/06/2019-05-06/
我就用人體的組成方式,來給大家示範一下
試試看在物件內的函式呼叫方式
component.callFamily
var component={
name:'俊仁',
deposit:1000,
members:{
kidney:'值錢的腎臟',
liver:'好用的肝臟,熬夜的好朋友!'
},
callFamily: function(){
console.log('聯絡俊仁');
}
};
console.log(component.callFamily);
// 顯示結果
'聯絡俊仁' component.members.kidney
var component={
name:'俊仁',
deposit:1000,
members:{
kidney:'值錢的腎臟',
liver:'好用的肝臟,熬夜的好朋友!'
},
callFamily: function(){
console.log('聯絡俊仁');
}
};
console.log(component.callFamily);
console.log(component.members.kidney);
// 顯示結果
'聯絡俊仁'
'值錢的腎臟' 這裡我們會試著寫寫看其他的方法,以下是編譯有通過的情況 ,試驗錯誤,就是了解的最好方法。
var component ={
name:'俊仁',
deposit:1000,
members:{
kidney:'值錢的腎臟',
liver:'好用的肝臟,熬夜的好朋友!'
},
1: '1',
'$-是俊仁': '$-俊仁 string',
callFamily: function(){
console.log('聯絡俊仁');
}
};
console.log(component.callFamily);
console.log(component.members.kidney);
console.log(1);
console.log(component.$-是俊仁);
console.log(component['$-是俊仁']);
// 顯示結果
'聯絡俊仁'
'值錢的腎臟'
1
['$-是俊仁'] 沒有定義! 得知一個結論
當你要呼叫屬性名稱時,屬性名稱可以為 = 數值、字串。
呼叫函式的方法就可以用標記法以及中括號。
var component ={
name:'俊仁',
deposit:1000,
members:{
kidney:'值錢的腎臟',
liver:'好用的肝臟,熬夜的好朋友!'
},
1: '1',
'$-是俊仁': '$-俊仁 string',
var component ={
name:'俊仁',
deposit:1000,
members:{
kidney:'值錢的腎臟',
liver:'好用的肝臟,熬夜的好朋友!'
},
1: '1',
'$-是俊仁': '$-俊仁 string',
callFamily: function(){
console.log('聯絡俊仁');
}
};
console.log(component.callFamily);
console.log(component.members.kidney);
console.log(1);
console.log(component['$-是俊仁']);
// 呼叫函式
component.callFamily();
component['callFamily']();
// 這2個是一樣的方法
// 顯示結果
'聯絡俊仁'
'值錢的腎臟'
1
['$-是俊仁'] 沒有定義!
'聯絡俊仁'
'聯絡俊仁'
進入新增屬性之後,我們一樣試試看一些寫法。
var component ={
name:'俊仁',
deposit:1000,
members:{
kidney:'值錢的腎臟',
liver:'好用的肝臟,熬夜的好朋友!'
},
1: '1',
'$-是俊仁': '$-俊仁 string',
callFamily: function(){
console.log('聯絡俊仁');
}
};
console.log(component.callFamily);
console.log(component.members.kidney);
console.log(1);
console.log(component['$-是俊仁']);
// 這2個是一樣的方法
// 呼叫函式
component.callFamily();
component['callFamily']();
// 新增屬性
component.lungs= "肺部";
component['spine'] ="脊椎";
console.log(component);
// 這2個是一樣的方法
// 顯示結果
'聯絡俊仁'
'值錢的腎臟'
1
['$-是俊仁'] 沒有定義!
'聯絡俊仁'
'聯絡俊仁'
將執行視窗內的物件屬性拉下去,會看到內部的屬性。
刪除componet 裡面的屬性
1.deposit
2.後來新增的[$$$]
delete component.屬性內容;
var component ={
name:'俊仁',
deposit:1000,
members:{
kidney:'值錢的腎臟',
liver:'好用的肝臟,熬夜的好朋友!'
},
1: '1',
'$-是俊仁': '$-俊仁 string',
callFamily: function(){
console.log('聯絡俊仁');
}
};
console.log(component.callFamily);
console.log(component.members.kidney);
console.log(1);
console.log(component['$-是俊仁']);
// 這2個是一樣的方法
// 呼叫函式
component.callFamily();
component['callFamily']();
// 新增屬性
component.lungs= "肺部";
component['spine'] ="脊椎";
// 刪除屬性
delete component.deposit;
delete component['$$$'];
console.log(component);
// 這2個是一樣的方法
// 顯示結果
'聯絡俊仁'
'值錢的腎臟'
1
['$-是俊仁'] 沒有定義!
'聯絡俊仁'
'聯絡俊仁'
import 與 export 在Node.js 有提到其用法: Node.js require、module以及exports 模組設定 - Hugo Habor 每一個Javascript檔案可當作獨立模組系統(ES Module) 1. Module(模組)…
作者今天遇到一個很奇怪的問題 寫程式寫到一半... 點擊應用程式時... 怎麼都跳不出畫面... 後來查詢了一下是Reg註冊可能被微軟更新給搞掉了... 文章資訊來源: 【以解決】各位.exe檔案打不開,不要相信"在 Windows 7 或 Windows Vista 中無法打開 .EXE 檔案"這篇文章…
Node.js可以提供你很多模組,今天來探索如何使用 Node.js 的 http 模組來架設一個簡單的伺服器。 本篇使用模組require 載入你所需要的模組。這次我們使用'http' 模組來創造一個簡單的server。 資料參考 Node.js - createServer 起手式 - iT…
針對Node.js來談談 require、module以及exports 模組設定。這些概念允許開發者將大型程序分解成小的、可管理的、可重用的部分,稱為模塊。 下面將逐一介紹這些概念,以及它們如何與 JavaScript 關聯。 An Essential Guide to Node.js Modules (javascripttutorial.net) 1. Module(模組)…
像是很多專案必須讀取國家資料中心的metadata,許多檔案格式為CSV、JSON、Html可以利用網頁技術去爬蟲;拿一個範例來嘗試看看就知道這些語法的實際用途。 [主題週]專題報導-開放資料 (Open Data)相關議題與應用 (114230) - Cool3c 在這裡我們使用台北市資料大平台 UBike2.0 作為資料依據! 目的 來抓取空位數量 >15, 抓取空位數量 <15。…