猿问

引入一个js文件报错TypeError: Cannot set property 'extend'

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>Title</title>


</head>

<body>


<script src="./aid.js"></script>

<script>

    function abc(){

        console.log('我是小abc')

    }


    var object1 = {

        apple: 0,

        banana: { weight: 52, price: 100 },

        cherry: 97

    };

    var object2 = {

        banana: { price: 200 },

        durian: 100

    };


    var object = Aid.extend({}, object1, object2);

</script>




</body>

</html>

LEATH
浏览 789回答 2
2回答

牛魔王的故事

Aid.fn.extend 报错,Aid.fn = Aid.prototype,但是Aid不是函数呀,Aid.prototype是undefined。再Aid.fn = Aid.prototype的后面console.log(Aid)看一下

呼啦一阵风

Aid 是一个object, 返回 { isFunction : isFunctionCharacter }, 他又不是一个构造函数, 你怎么在他的原型里添加方法?Aid是模仿jquery做的一个方法吧? 那么var Aid = function() {&nbsp; &nbsp; var isFunctionCharacter = function(obj)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(typeof obj === "function") { //是函数&nbsp; &nbsp; 其中 FunName 为函数名称&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log("is function");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { //不是函数&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log("not is function");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; } catch(e) {}&nbsp; &nbsp; }&nbsp; &nbsp; return { isFunction : isFunctionCharacter };}// ();这里的立即执行应该去掉吧, 这样应该可以
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答