总体源码:
'use strict'
function defineReactive ( data , key , val ){
let childOb = observe(val);
let dep = new Dep() ; //** this dep only use for the Object-kind 's data ;
Object.defineProperty( data , key , {
enumerable : true ,
configurable : true ,
get function () {
dep.depend(); //** this dep only use for the Object-kind 's data ; to collect depend of Object ;
if(childOb){
//to collect depend of Array-kind ;
childOb.dep.depend();
}
return val ;
},
set function (newVal) {
//** the set only use for the Object-kind 's data ;
if( val === newVal ){
return ;
}
dep.notify() ;
val = newVal ;
}
});
}
//create a interception :
const arrayProto = Array.prototype ;
const arrayMethods = Object.create(arrayProto);
[
'push',
'pop',
'shift',
'unshift',
'splice',
'sort',
'reverse'
].forEach( function (method){
//to buffer the original methods:
const original = arrayProto[method];
def( arrayMethods , method , function mutator (...args){
const result = original.apply(this,args);
const ob = this._ob_ ;
let inserted ;
switch (method) {
case 'push' :
case 'unshift':
inserted = args ;
break ;
case 'splice':
inserted = args.slice(2);
break ;
}
if( inserted ) ob.observeArray( inserted );
ob.dep.notify();
return result ;
} )
});
//to create a converter :
class Observer {
constructor (value) {
/* the executing procerdure : */
this.value = value ;
this.dep = new Dep();
def(value,'_ob_',this);
// to process the Object-king/Array-kind elements inside the array sequence ;
if (Array.isArray(value)) {
this.observeArray(value);
} else {
this.walk(value);
}
//
if (Array.isArray(value)) {
const augment = hasProto
?protoAugment
:copyAugment ;
augment( value , arrayMethods , arrayKeys );
} else {
this.walk(value);
}
}
/*----------------------------------------------------------*/
/* to define the prototype method of Observe-kind: */
// method for scrutinizing the array to find that if there is have any element can be further converted :
observeArray (items) {
for( let i = 0 , l = items.length ; i < l ; i++ ){
observe(items[i]) ;
}
}
//the method walk will converte a Object-case 's all data-kind property into the kind of accessors(setter/getter); ! invoke it only by Object-kind
walk (obj){
const keys = Object.keys(obj);
for( let i = 0 ; i < keys.length ; i++ ){
defineReactive( obj , keys[i] , obj[keys[i]]);
}
}
}
/**global method : */
// to create a def tool which smplify the operation of defineProperty that data-property :
function def (obj,key,val,enumerable){
Object.defineProperty(obj,key,{
value : val ,
enumerable : !!enumerable ,
writable : true ,
configurable : true
});
}
function observe ( value , asRootData ){
if( !isObject(value) ) {
return ;
}
let ob ;
if ( hasOwn(value,'_ob_') && value._ob_ instanceof Observer ) {
ob = value._ob_ ;
} else {
ob = new Observer(value);
}
return ob ;
}
提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
提示:以下是本篇文章正文内容,下面案例可供参考
示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。
代码如下(示例):
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
代码如下(示例):
data = pd.read_csv(
'https://labfile.oss.aliyuncs.com/courses/1283/adult.data.csv')
print(data.head())
该处使用的url网络请求的数据。
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。