EMCA262瑙勮寖涓病鏈夌被(class)鐨勬蹇碉紝js鐨刵ew鍙槸璁╀粬鐪嬭捣鏉ユ洿鍍廲++,java涓鐐广傝繖閲岃鐨勫啓绫伙紝鍙槸涔﹀啓js浠g爜椋庢牸鑰屽凡銆
1銆佹瀯閫犲嚱鏁版柟寮
鏂囩珷鏉ヨ嚜 codego.net 璇风湅婧愪唬鐮:
/**
* Person绫伙細瀹氫箟涓涓汉锛屾湁涓睘鎬ame锛屽拰涓涓猤etName鏂规硶
* @param {String} name
*/
function Person(name) {
this.name = name;
this.getName = function() {
return this.name;
}
}
杩欑椋庢牸璁╂垜浠繖浜涘啓杩噅ava鐨勬湁鐐逛翰鍒囧湪浜庢瀯閫犱竴涓璞¢渶瑕侀厤缃竴浜涘弬鏁帮紝鍙傛暟瑕佽祴鍊肩粰绫婚噷闈his銆備絾涓巎ava鐨勫尯鍒槸js鐢╢unction鏉ュ畾涔夌被,--codego.net--锛屽弬鏁颁篃鏃犻渶瀹氫箟绫诲瀷銆
绫诲啓濂戒簡锛屾垜浠犲嚑涓璞★細
鏂囩珷鏉ヨ嚜 codego.net 璇风湅婧愪唬鐮:
var p1 = new Person("Jack");
var p2 = new Person("Tom");
console.log(p1 instanceof Person);//true
console.log(p2 instanceof Person);//true
鎺у埗鍙拌緭鍑轰篃璇佹槑浜唒1锛宲2鐨勭‘鏄被Person鐨勫璞″疄渚嬨
杩欑鏂瑰紡鐨勪紭鐐规槸锛氬彲浠ユ牴鎹弬鏁版潵鏋勯犱笉鍚岀殑瀵硅薄瀹炰緥 锛岀己鐐规槸鏋勯犳椂姣忎釜瀹炰緥瀵硅薄閮戒細鐢熸垚getName鏂规硶鐗堟湰锛岄犳垚浜嗗唴瀛樼殑娴垂 銆
褰撶劧缁忛獙涓板瘜鐨勭▼搴忓憳鐢ㄤ竴涓閮ㄥ嚱鏁版潵浠f浛绫绘柟娉曪紝杈惧埌浜嗘瘡涓璞″叡浜悓涓涓柟娉曘傛敼鍐欏悗鐨勭被濡備笅锛
鏂囩珷鏉ヨ嚜 codego.net 璇风湅婧愪唬鐮:
//澶栭儴鍑芥暟
function getName() {
return this.name;
}
function Person(name) {
this.name = name;
this.getName = getName;//娉ㄦ剰杩欓噷
}
鍛靛懙锛屾湁浜哄彲鑳借寰椾唬鐮侀鏍兼湁鐐瑰樊寮轰汉鎰忥紝鎬庝箞鐪嬩篃娌℃湁java閭d箞绱у噾銆備絾鐨勭‘鍙互鍑忓皯鍐呭瓨鐨勬秷鑰椼
分享题目:varp1=newPerson
本文路径:
http://cqcxhl.com/article/ihdhoo.html